diff --git a/README.md b/README.md index 7dbfc45..872db93 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,20 @@ -# {service} +# Basic Banking -{description} +This Monolith is pretend to be different services, it also Postgres 18rc1 to have access to UUIDv7. ## Properties For Deployment -| Name | Required | Information | -|------------------------|:--------:|-------------------------| -| spring.profiles.active | ✔ | Spring Boot environment | +| Name | Required | Information | +|-------------------------------|:--------:|-------------------------| +| spring.profiles.active | ✔ | Spring Boot environment | +| spring.r2dbc.url | ✔ | Postgres host url | +| spring.r2dbc.username | ✓ | Postgres username | +| spring.r2dbc.password | ✱ | Postgres password | +| server.port | | HTTP port | +| server.ssl.enabled | | HTTP Enable SSL | +| server.ssl.key-store | ✗ | HTTP Keystore | +| server.ssl.key-store-type | | HTTP Cert Type | +| server.ssl.key-store-password | ✱ | HTTP Cert Pass | *Required:* @@ -14,6 +22,10 @@ - *✗ mounted file.* - *✱ need to be stored as secret.* +## Development + +Use `development-compose.yml` to set up needed external dependencies. + ## Releasing Service Run release pipeline from `master` branch. diff --git a/build.gradle.kts b/build.gradle.kts index d1695fc..93f835f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,14 +12,19 @@ dependencies { implementation(aa.kotlin.reflect) implementation(aa.kotlinx.coroutines) implementation(aa.springboot.starter.actuator) + implementation(aa.springboot.starter.r2dbc) implementation(aa.springboot.starter.webflux) + runtimeOnly(aa.postgresql) + runtimeOnly(aa.postgresql.r2dbc) + testImplementation(aa.kotlin.junit5) testImplementation(aa.kotlinx.coroutines.test) + testImplementation(aa.mockk) testImplementation(aa.springboot.starter.test) testRuntimeOnly(aa.junit.platform.launcher) } group = "ltd.lulz" -description = "service template" +description = "service basic banking" diff --git a/development-compose.yml b/development-compose.yml new file mode 100644 index 0000000..fa3ffd7 --- /dev/null +++ b/development-compose.yml @@ -0,0 +1,24 @@ +name: develop + +networks: + develop: + name: develop + external: true + +volumes: + postgres: + +services: + postgres: + image: postgres:18rc1-alpine + container_name: postgres + restart: unless-stopped + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + ports: + - 5432:5432 + networks: + - develop + volumes: + - postgres:/var/lib/postgresql/data diff --git a/gradle.properties b/gradle.properties index 918eb4b..62ca361 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,5 @@ version=0.1.0-SNAPSHOT -catalog=0.1.0 +catalog=0.2.0-SNAPSHOT +docker.port.expose=8443 +container.port.expose=8443 +container.port.host=8443 diff --git a/http/actuator.http b/http/actuator.http new file mode 100644 index 0000000..0058446 --- /dev/null +++ b/http/actuator.http @@ -0,0 +1,3 @@ +### Actuator + +GET {{url}}/actuator diff --git a/http/http-client.env.json b/http/http-client.env.json new file mode 100644 index 0000000..26984d1 --- /dev/null +++ b/http/http-client.env.json @@ -0,0 +1,11 @@ +{ + "develop": { + "url": "http://localhost:8080" + }, + "docker": { + "url": "https://localhost:8443" + }, + "kubernetes": { + "url": "https://10.0.0.0" + } +} diff --git a/instructions.md b/instructions.md new file mode 100644 index 0000000..bc72022 --- /dev/null +++ b/instructions.md @@ -0,0 +1,20 @@ +# Senior Engineer Test + +### **Develop a service that simulates basic banking operations in a programming language of your choice. This service will manage accounts, process deposits, withdrawals, and transfers between accounts.** + +### The system should be designed reflecting real-world constraints of a bank. + +## Requirements: + +1. A class or set of functions that allow: + * Account creation: Allow users to create an account with an initial deposit. + * Deposit: Enable users to deposit money into their account. + * Withdrawal: Allow users to withdraw money from their account, ensuring that overdrafts are not allowed. + * Transfer: Enable transferring funds between accounts. + * Account balance: Provide the ability to check the account balance. +2. Database: + * In-memory data storage will suffice, no need to have a database alongside the project, but you can add one at your discretion + +The word “service” here is used in a “software component/module” rather “deployable unit with an API” sense, no need to provide API for it. + +## Feel free to take as along as you need to complete the exercise. This will be used as a base for a follow-up pair programming session. diff --git a/settings.gradle.kts b/settings.gradle.kts index a4d35d0..7aa7f63 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -34,4 +34,4 @@ pluginManagement.repositories { gradlePluginPortal() } -rootProject.name = "service" +rootProject.name = "basic-banking" diff --git a/sql/initial/000-initizalise.sql b/sql/initial/000-initizalise.sql new file mode 100644 index 0000000..0e59659 --- /dev/null +++ b/sql/initial/000-initizalise.sql @@ -0,0 +1,64 @@ +-- Role: role_administrator +-- DROP ROLE IF EXISTS role_administrator; + +CREATE ROLE role_owner; + + +-- Role: role_service +-- DROP ROLE IF EXISTS role_service; + +CREATE ROLE role_service; + + +-- Role: role_maintainer +-- DROP ROLE IF EXISTS role_maintainer; + +CREATE ROLE role_maintainer; + + +-- Role: support_role +-- DROP ROLE IF EXISTS support_role; + +CREATE ROLE role_support; + + +-- User: services +-- DROP USER IF EXISTS services; + +CREATE USER service WITH PASSWORD 'password'; + +-- Assign role to the user +GRANT role_service TO service; + + +-- User: user_maintainer +-- DROP USER IF EXISTS user_maintainer; + +CREATE USER user_maintainer WITH PASSWORD 'password'; + +-- Assign role to the user +GRANT role_maintainer TO user_maintainer; + + +-- User: user_support +-- DROP USER IF EXISTS user_support; + +CREATE USER user_support WITH PASSWORD 'password'; + +-- Assign role to the user +GRANT role_support TO user_support; + + +-- Database: basic_banking +-- DROP DATABASE IF EXISTS basic_banking; + +CREATE DATABASE basic_banking + WITH + OWNER = role_owner + ENCODING = 'UTF8' + TABLESPACE = pg_default + CONNECTION LIMIT = -1 + IS_TEMPLATE = False; + +COMMENT ON DATABASE basic_banking + IS 'Database for basic banking, registered account and transactions.'; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 045a197..0dc690b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -24,6 +24,13 @@ management: exposure: include: "health,info" +server: + port: 8443 + ssl: + enabled: true + key-store: classpath:cert/keystore.p12 + key-store-type: PKCS12 + --- ########################### ### Develop environment ### @@ -32,6 +39,16 @@ spring: config: activate: on-profile: develop + r2dbc: + url: r2dbc:postgresql://localhost:5432/basic_banking + username: service + password: password + +server: + port: 8080 + ssl: + enabled: false +# key-store-password: password --- ########################## @@ -41,6 +58,14 @@ spring: config: activate: on-profile: docker + r2dbc: + url: r2dbc:postgresql://postgres:5432/basic_banking + username: service + password: password + +server: + ssl: + key-store-password: password --- ############################## @@ -50,3 +75,5 @@ spring: config: activate: on-profile: kubernetes + r2dbc: + url: r2dbc:postgresql://postgres:5432/basic_banking diff --git a/src/main/resources/cert/keystore.p12 b/src/main/resources/cert/keystore.p12 new file mode 100644 index 0000000..38735ad Binary files /dev/null and b/src/main/resources/cert/keystore.p12 differ