simple-bank

module
v0.0.0-...-308d6b8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2021 License: GPL-3.0

README ΒΆ

:moneybag: Simple Bank :moneybag:

Simple Bank is a simple REST API that allows users to perform transferences with each other.

πŸ”§ Technologies

  • Golang
  • Docker
  • PostgreSQL
  • Github actions

πŸ“š Libraries

🚩 Endpoints

/accounts

/api/v1/accounts - POST Creates a new account. Example of request body:

{
  "name": "Maria",
  "secret": "12345678",
  "cpf": "103.913.350-90"
}

/api/v1/accounts - GET Fetch all accounts

/api/v1/accounts/{account_id}/balance - GET Get the account's balance

Details

  • Accounts endpoints does not require authentication
  • New accounts starts with 1000 in its balance
  • The account's balance is always integer
  • The cpf field should match xxx.xxx.xxx-xx. Take a look at this website for generate random cpfs.
  • The secret field must have between 6 and 50 characters

/login

/api/v1/login - POST Creates a JWT token. Example:

// Request body
{
	"cpf": "084.792.650-86",
	"secret": "12345678"
}
// Response
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJFeHBpcmVzQXQiOjE1MDAsIklkIjoiZGY2YWNlODktNGE0Yy00NGY5LTk3OGMtNTIxMTEzNDEwMDM1IiwiSXNzdWVkQXQiOjE2MjA1MTE0Mjl9.v1kzBo3GdIXO1vhTq9_icIgfdgE7981KZ5CaQlw3Bvs"
}

/transfers

/api/v1/transfers - POST Perform a transference between two accounts. Example:

// Request body
{
  "account_destination_id": "eb7b34eb-643b-4e2b-9e81-7641b3e45327",
  "amount": 100
}
// Response body
{
  "id": "6e5d9213-2c86-4cb8-bfc7-ddafd9237d34",
  "account_destination_id": "eb7b34eb-643b-4e2b-9e81-7641b3e45327",
  "account_origin_id": "df6ace89-4a4c-44f9-978c-521113410035",
  "amount": 100,
  "created_at": "2021-05-08T22:06:18.439343Z"
}

/api/v1/transfers - GET Get the transferences of the authenticated user

Details

  • Bearer token is required to perform requests
  • The account_origin_id comes from the authenticated user, and can't be equal the account_destination_id (make a transference to yourself does not make sense)
  • The authenticated user must have sufficient funds to perform a transference

🏁 How to run (needs Docker 🐳)

  • Copy the .env.example file content into a new file called .env
  • After using make dev-local or make dev-docker, the API will be available in http://localhost:3000/api/v1

Running the application locally using Go and Docker

  make dev-local

Running with Docker (Go not required)

  make dev-docker

🚦 Testing

Run tests

  make test

See test coverage

  make test-coverage

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL