From 12bc74c1e60c28385c1b9d7c8c4ad334baf0a0a8 Mon Sep 17 00:00:00 2001 From: Swordsteel Date: Thu, 11 Sep 2025 10:31:23 +0200 Subject: [PATCH] add account data - AccountRepository - AccountEntity - 001-accounts.sql - Account with Request and Response --- sql/initial/001-accounts.sql | 21 +++++++++++++++++++ src/main/kotlin/ltd/lulz/model/Account.kt | 17 +++++++++++++++ .../kotlin/ltd/lulz/model/AccountEntity.kt | 14 +++++++++++++ .../ltd/lulz/repository/AccountRepository.kt | 9 ++++++++ 4 files changed, 61 insertions(+) create mode 100644 sql/initial/001-accounts.sql create mode 100644 src/main/kotlin/ltd/lulz/model/Account.kt create mode 100644 src/main/kotlin/ltd/lulz/model/AccountEntity.kt create mode 100644 src/main/kotlin/ltd/lulz/repository/AccountRepository.kt diff --git a/sql/initial/001-accounts.sql b/sql/initial/001-accounts.sql new file mode 100644 index 0000000..5a0577e --- /dev/null +++ b/sql/initial/001-accounts.sql @@ -0,0 +1,21 @@ +-- Table: public.accounts +DROP TABLE IF EXISTS public.accounts; + +CREATE TABLE IF NOT EXISTS public.accounts +( + id UUID DEFAULT uuidv7(), + name VARCHAR(50) NOT NULL, + amount NUMERIC(19, 2) NOT NULL, + CONSTRAINT pk_contact_types PRIMARY KEY (id) +); + +ALTER TABLE IF EXISTS public.accounts + OWNER to role_owner; + +-- Revoke all permissions from existing roles +REVOKE ALL ON TABLE public.accounts FROM role_service, role_support; + +-- Grant appropriate permissions +GRANT ALL ON TABLE public.accounts TO role_maintainer; +GRANT SELECT, INSERT, UPDATE ON TABLE public.accounts TO role_service; +GRANT SELECT ON TABLE public.accounts TO role_support; diff --git a/src/main/kotlin/ltd/lulz/model/Account.kt b/src/main/kotlin/ltd/lulz/model/Account.kt new file mode 100644 index 0000000..9265aad --- /dev/null +++ b/src/main/kotlin/ltd/lulz/model/Account.kt @@ -0,0 +1,17 @@ +package ltd.lulz.model + +import java.math.BigDecimal +import java.util.UUID + +object Account { + data class Request( + val name: String, + val amount: BigDecimal, + ) + + data class Response( + val id: UUID, + val name: String, + val amount: BigDecimal, + ) +} diff --git a/src/main/kotlin/ltd/lulz/model/AccountEntity.kt b/src/main/kotlin/ltd/lulz/model/AccountEntity.kt new file mode 100644 index 0000000..51518ac --- /dev/null +++ b/src/main/kotlin/ltd/lulz/model/AccountEntity.kt @@ -0,0 +1,14 @@ +package ltd.lulz.model + +import java.math.BigDecimal +import java.util.UUID +import org.springframework.data.annotation.Id +import org.springframework.data.relational.core.mapping.Table + +@Table("accounts") +data class AccountEntity( + @Id + val id: UUID? = null, + val name: String, + val amount: BigDecimal, +) diff --git a/src/main/kotlin/ltd/lulz/repository/AccountRepository.kt b/src/main/kotlin/ltd/lulz/repository/AccountRepository.kt new file mode 100644 index 0000000..350b996 --- /dev/null +++ b/src/main/kotlin/ltd/lulz/repository/AccountRepository.kt @@ -0,0 +1,9 @@ +package ltd.lulz.repository + +import java.util.UUID +import ltd.lulz.model.AccountEntity +import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository + +@Repository +interface AccountRepository : ReactiveCrudRepository