I made this project for Link Aja Assignment
This project was made using:
- Go (main language of this project)
- MySQL (main database)
- sqlite3 (temporary database for unit testing)
- Go (This was made in go1.15.5)
- MySQL / MariaDB
- Import the database provided in database/db.sql file
- Important If you're executing with docker, you don't need to change anything in .env file. You can just skip step 3 and 4
- Inside .env file, there are configurations needed for the api to run,
change them according to your system. The most important variable that
you have to change is:
- DB_USER - DB_PASSWORD - API_HOST (optional) - API_PORT (optional)
- (Optional) Install
make
program for your system
- Launch your terminal
- Go to the directory of this project
- Type
docker-compose up --build
- If you got error listen tcp 0.0.0.0:3306: bind: address already in use, you have to stop mysql service first..
- For linux run this in your terminal
systemctl stop mysql
- For Windows run this in your command prompt
net stop MySQL
- If the commands doesn't work, you need to search how to stop mysql service for your OS.
- If you any error after executin
docker-compose up --build
try to run it withsudo
so the command should be something like thissudo docker-compose up --build
- Launch your terminal
- Go to the directory of this project
- Type
make dev
in the terminal. If your terminal says make command not found, make sure to install it first on your system - If everything is right, the output should be something like this
$ make dev go run main.go 2020/12/05 05:36:36 [MySQL] Database connected, simple_rest_la 2020/12/05 05:36:36 Starting Web Server at localhost port: 8080 Available endpoints: /account/{account_number} [GET] /account/{from_account_number}/transfer [POST] ``` <br>
Returns json data about a single account.
-
URL
/account/{account_number}
-
Method:
GET
-
URL Params
Required:
account_number=[string]
-
Data Params
None
-
Success Response:
- Code: 200
- Content:
{ "account_number": "555001", "customer_number": "1001", "balance": "10000" }
- Code: 200
-
Error Response:
- Code: 404
- Content:
{ "message": "Data not found", "error_code": 404 }
- Code: 404
Transfer money from an account to another account.
-
URL
/account/{from_account_number}/transfer
-
Method:
POST
-
URL Params
Required:
from_account_number=[string]
-
Data Params
{ "to_account_number": "555002", "amount": "100" }
-
Success Response:
- Code: 201
- Content: None.
- Code: 201
-
Error Response:
- Code: 400
- Content:
{ "message": "Decoding json failed", "error_code": 400 }
OR
- There are multiple error message with code 404, this is one of them
- Code: 404
- Content:
{ "message": "Your Balance is not enough", "error_code": 404 }
- Code: 400