Giter Club home page Giter Club logo

brandbank-api's Introduction

BrandBanking API

An api which allows trasactions crediting ou debiting user's balance

๐Ÿ“š Features:

  • User's Registration: Allows users registration. Payload example:
{
  "email": "[email protected]",
  "name": "John",
  "password": "123",
  "age": 23,
  "address": "Street alamedas"
}

The user's account code is generated automatically.

  • Post Transactions: allows users to move their balance by launching transactions, crediting or debiting the balance.
POST /transactions/debt/{value}
i.e.
/transactions/debt/1.23
POST /transactions/credt/{value}
i.e.
/transactions/credt/8.17
  • Check users transactions: allows users to consult all transactions carried out in a paged format.
GET /transactions?{paginationParameters}
i.e.
/transactions?page=0&linesPerPage=10&direction=DESC&orderBy=created_at
  • Swagger: allows to see all API's endpoints, allowing to an authentication token to test and see the expected payloads from each endpoint.
Enter the url:
http://localhost:8080/swagger-ui/index.html
  • Authentication & Authorization: The API implemented JWT authentication, all endpoints require a JWT except

/users/register : Registration endpoint

/login : Authentication endpoint

/swagger-ui/index.html : Swagger endpoint

Authentication payload:

{
  "accountCode": "12760.00",
  "password": "123"
}

More details about autenticated routes at SecurityConfig.java:

๐Ÿ“‹ Backlog

The project uses Github Projects as a development board to save all features on Backlog:

๐Ÿ’ป Entity relationship diagrams

erDiagram
    TB_USER {
        String id PK
        String accountCode
        String password
        Integer role
        String email
        String name
        Integer age
        String address
        Datetime createdAt
    }
    
    TB_CUSTODY {
        String id PK
        BigDecimal balance
        BigDecimal balance_limit
        String user_id FK
    }
    
    TB_TRANSACTIONY {
        String id PK
        Integer movement
        BigDecimal movementValue
        Datetime createdAt
        String custody_id FK
    }
    
    TB_USER ||--|| TB_CUSTODY : has
    TB_CUSTODY ||--o{ TB_TRANSACTIONY : has
Loading

๐Ÿ”ง Dependencies

The project requires Maven, Java 17 and a Postgrees database to run the projects Thus, the projects uses those enviroment keys:

JWT_SECRET=;
SPRING_DATASOURCE_IP=<ip>:<port>
SPRING_DATASOURCE_DBNAME=/brandbank;
SPRING_DATASOURCE_SCHEAMA=?currentSchema=public;
SPRING_DATASOURCE_USERNAME=;
SPRING_DATASOURCE_PASSWORD=;

The project provides a "dev" execution profile that uses the H2 in-memory database, in this profile it is not necessary to perform any connection configuration

To use the dev profile, change the application.properties: file as follows

spring.profiles.active=dev

๐Ÿš€ Running

The api provides a bunch of docker-compose files which allows a quick setup for a local running or a test enviroment running.

๐Ÿ› ๏ธ Local run

Once you installed docker, open the command prompt at directory /docker and run docker-compose command to start up.

docker compose up

By running this command it uses 3 files

  • Dockerfile: a custom image which compiles project's binaries and runs using a jre image
  • docker-compose.yml: which names the custom docker file
  • docker-compose.override.yml: which segregates containers configurations such as enviroments variables, profiles, exposed ports and more. It automatically runs after docker-compose.yml. By default it runs at :8080but it is possible to change setting up this file.

With that it is possible to test using swagger at Swagger-ui:

To clean up after execution use:

docker compose down

๐Ÿงช Enviroment run

To simulate an enviroment it uses postgree's database to persist data even after closing the application.

This approach requires an additional configuration of docker. It uses others features of docker such as secrets which requires enabbling docker swarm.

Currently to enable docker swarm run the command below, it will not only enable swarm but also create a manager node which will run our services. At docker swarm services are equivalent to containers in terms of abstraction, check out docker docs to explore about it.

docker swarm init 

Once enabled swarm, the next step is to set up services' secrets running the commands below in CLI.

echo "dbUser" | docker secret create psql_user -
echo "dbname" | docker secret create psql_db -
echo "mydbpass" | docker secret create psql_password -
echo "bank" | docker secret create psql_scheama -

Then run the command below to startup the enviroment.

docker stack deploy -c docker-compose.test.yml test_env

To check whether both postgree and application are up run the command below

docker service ps test_env_postgres test_env_spring-brandbank-api

With that it is possible to test using swagger at Swagger-ui:

In order to clean up after execution use:

docker stack rm test_env
docker volume rm test_env_psql-data
docker secret rm psql_db psql_password psql_scheama psql_user

brandbank-api's People

Contributors

aritedeschi avatar

Watchers

 avatar

brandbank-api's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.