This is a challenge set by a company and solved by Carlos Damázio (github.com/carlosdamazio).
I was asked to create a payment API REST in Go programming language, that obeys some of it's constraints regarding code delivery, code quality, documentation and clean code. In this implementation, an Account and Transfer representation must be specified in order to create a payment environment.
This project consists of a REST API with a Dockerfile and docker-compose.yml file to make the environment easier to set up. It also uses a MongoDB, a NoSQL database to store all Accounts and Transfer entities.
$ docker-compose up -d --build
# It will run on localhost:8080
# To stop the project...
$ docker-compose down
Online specs may be seen here.
Rule of thumb: JSON format only.
- id
- name
- cpf
- balance
- created_at
- Request body: None;
- Response: List of Accounts.
- Request body: None;
- Response: Account balance.
- Request body: "name" and "cpf", all required;
- Response: CREATED if serialization is OK or BAD REQUEST if not.
- Balance might be initialized with any value to make it simple (default is 30).
- id
- account_origin_id
- account_destination_id
- amount
- created_at
- Request body: None;
- Response: List of Transfers.
- Request body: "originAccount", "destAccount" and "amount", all required;
- Response: CREATED if serialization is OK and follows business constraints or BAD REQUEST if not.
- Must update both accounts balances presented in a transfer;
- If the transfer requester (origin account) doesn't have enough funds, must return an error code.