A RESTful API that processes transactions.
This project uses:
- Go as the coding language.
- PostgreSQL as the database.
flowchart LR
api[Go app\nHTTP API]
db[(PostgreSQL\ndatabase)]
api <-... Write/Read Operations ...-> db
The expected inputs for the application should come as HTTP requests, for each specific resource/endpoint:
Create an Account:
POST /accounts
Request body:
{
"document": "12345678900"
}
Reads an Account, based on an ID:
GET /accounts/{:accountID}
Create a Transaction:
POST /transactions
Request body:
{
"account_id": 1,
"operation_id": 1,
"amount": 543.21
}
Some notes about what I'd thought would be nice to the project.
- In the extras folder, you can find 2 files to use with Postman: a Collection and an Environment.
- I've noticed several flaws in the choice of how to work with databases: breaking interface/abstraction rules, usage of transactions/commits/rollbacks, etc. In a next scenario, it will be a better choice to use something that already exists instead of trying to reinvent the wheel 😉
This project offers a local environment to get this project up and running. This environment should be used only for local development/execution.
In order to use this environment, first make sure you have the tools below correctly installed:
TOOL | VERSION* |
---|---|
Git** | 2.34.1 |
Docker | 24.0.6 (linux/amd64) |
Docker Compose | Docker Compose version v2.21.0 |
Make | GNU Make 4.3 (x86_64-pc-linux-gnu) |
*: these are suggested versions, for a Linux environment. It will (probably) have no issues in Mac OS, but It may (or not) work using other versions/OSs. **: required to clone this repository 😉
Also important: the local environment will try to use ports 8080 (API) and 5432 (database). Before start, check if these ports are available. If not, you can select other ports by changing them in the docker-compose.yml file.
Once you're OK with the steps on Prerequisites, you can follow the actions below:
- Using your terminal, navigate to this project's root folder.
- In the same terminal windown, copy the file
env/.env.sample
toenv/.env
. You can run the command below in your terminal:
cp env/.env.sample env/.env
- Also in the same terminal window, run the command below:
make start
This command will:
- Pull/build the required images.
- Start the database server.
- Create the application's database.
- Start the application at 0.0.0.0:8080.
- Using your terminal, navigate to this project's root folder.
- In the same terminal window, run the command below:
make stop
- Using your terminal, navigate to this project's root folder.
- In the same terminal window, run the command below:
make tests