Skip to content

A banking application written in Go. It features a PostgreSQL db, a REST API with authentication, and docker containerization.

License

Notifications You must be signed in to change notification settings

JohannSuarez/GoBank

Repository files navigation

GoBank

This project is a back-end and CI/CD exercise in the form of a Banking app for practicing several frameworks and technologies such as Gin, PostgreSQL, Docker, and Kubernetes.

The Database

The database is comprised of four tables: entries, users, accounts, and transfers. Below is the schema illustration.

A user must register with a username, password, full name, and e-mail. Once registered and logged in, a user can create multiple bank accounts, each being able to hold a different currency ( i.e. CAD, USD, EUR ).

Users may perform transfers with their accounts, and a transfer is recorded that features the account ID of the sender, the receiver, the amount transferred, and the transfer timestamp.

With each transfer, two entries are created. One records the amount deduction from the sender and the other records the amount increase on the receiver's Account.

The RESTful API

The API is made using the Gin framework with middleware implemented to allow for JSON Web Token and PASETO authentications. Gin then uses Go code generated by SQLC, which converts SQL queries into CRUD code for Go. Each endpoint is tested using Gomock.

Continuous Integration Workflows

The project has two Github workflows located in .github/workflows/ that manage continuous integration.

test.yml - When a pull request is made towards the main branch, the unit tests are ran with a containerized PostgreSQL db. The pull request can be approved if all tests pass.

deploy.yml - Builds the Docker image,pushes it into Amazon ECR, and finally deploys it into Amazon EKS as the live production environment.

Interact With The App

Create a User by sending a POST request to https://api.justsimplebank.com/users This can be done using curl:

curl --location --request POST 'https://api.justsimplebank.com/users/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "MrWard",
    "password": "Namast3",
    "full_name": "Howard Hamlin",
    "email": "howard_hamlin@hhm.org"
}'

Log in with the User credentials you have created through https://api.justsimplebank.com/users/login .

curl --location --request POST 'https://api.justsimplebank.com/users/login' \
      --header 'Content-Type: application/json' \
      --data-raw '{
      "username": "MrWard",
      "password": "Namast3"
  }'

The response will contain an access token that you require for creating bank accounts.

Create a bank account for CAD currency by following this command, but be sure to replace the authorization token with the unique one you received from your own login request. The endpoint is https://api.justsimplebank.com/accounts/ .

curl --location --request POST 'https://api.justsimplebank.com/accounts/' \
--header 'Authorization: Bearer v2.local.b81-eBRSZKDVhpAtCzio9XqNowq45skiZZSNXHW46tV55LB5wdFaupLlZTU_230pGmaRo4PeypKQyQGXg6zEJZXyTL9NdEJ47oHYAuKp0kxzsVnDtC8Dg7hfexfgHnIKffrqr8RiV7wFqaIl9NSRl3TeGmL_nrOqfkOCI84VZFr_eQDAGS5_T4ZFr2Jw-cfKjkiH43defU5WCQVBPEogY9KXFvK6iL97BWD9YnTxC7UdkxxyZKIV0uLX6sAnh2udky_xVQ.bnVsbA' \
--header 'Content-Type: application/json' \
--data-raw '{
    "Currency": "CAD"
}'

The response will contain an account ID that you can use for transferring balances, provided that the recipient account is of the same currency. The endpoint is https://api.justsimplebank.com/transfers .

curl --location --request POST 'https://api.justsimplebank.com/transfers' \
--header 'Authorization: Bearer v2.local.b81-eBRSZKDVhpAtCzio9XqNowq45skiZZSNXHW46tV55LB5wdFaupLlZTU_230pGmaRo4PeypKQyQGXg6zEJZXyTL9NdEJ47oHYAuKp0kxzsVnDtC8Dg7hfexfgHnIKffrqr8RiV7wFqaIl9NSRl3TeGmL_nrOqfkOCI84VZFr_eQDAGS5_T4ZFr2Jw-cfKjkiH43defU5WCQVBPEogY9KXFvK6iL97BWD9YnTxC7UdkxxyZKIV0uLX6sAnh2udky_xVQ.bnVsbA' \
--header 'Content-Type: application/json' \
--data-raw '{
    "from_account_id": 3,
    "to_account_id": 2,
    "amount": 100,
    "currency": "CAD"
}'

About

A banking application written in Go. It features a PostgreSQL db, a REST API with authentication, and docker containerization.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published