Skip to content

devdrops/payments-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Payments API

A RESTful API that processes transactions.

Index

Concepts

This project uses:

flowchart LR
    api[Go app\nHTTP API]
    db[(PostgreSQL\ndatabase)]
    api <-... Write/Read Operations ...-> db
Loading

The expected inputs for the application should come as HTTP requests, for each specific resource/endpoint:

Accounts

Create an Account:

POST /accounts

Request body:
{
  "document": "12345678900"
}

Reads an Account, based on an ID:

GET /accounts/{:accountID}

Transactions

Create a Transaction:

POST /transactions

Request body:
{
  "account_id": 1,
  "operation_id": 1,
  "amount": 543.21
}

Extras

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 😉

Execution

Prerequisites

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.

How to Run

Once you're OK with the steps on Prerequisites, you can follow the actions below:

  1. Using your terminal, navigate to this project's root folder.
  2. In the same terminal windown, copy the file env/.env.sample to env/.env. You can run the command below in your terminal:
cp env/.env.sample env/.env
  1. Also in the same terminal window, run the command below:
make start

This command will:

  1. Pull/build the required images.
  2. Start the database server.
  3. Create the application's database.
  4. Start the application at 0.0.0.0:8080.

How to Stop

  1. Using your terminal, navigate to this project's root folder.
  2. In the same terminal window, run the command below:
make stop

How to Run Tests

  1. Using your terminal, navigate to this project's root folder.
  2. In the same terminal window, run the command below:
make tests

About

An API that handles paymenttransactions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published