Topic: The user has a balance in the application wallet and the balance wants to be disbursed.
● Write code in Golang
● Write API (only 1 endpoint) for disbursement case only
● User data and balances can be stored as hard coded or database
- disburse (user_id [int], amount [float])
- case:
- disbursement success [200]
- insufficient balance [400]
- invalid request [400]
- any internal error [500]
- case:
for detailed request & response please check Sample Request & Response
section.
- sqlite
- data model & initiated data:
users
table:
- data model & initiated data:
id | balance |
---|---|
1 | 10000000 |
2 | 20000000 |
3 | 25000000 |
for table schema check here: https://github.com/rizanw/disburse-app/blob/main/internal/repo/db/module/schema.go
id | balance |
---|---|
1 | 10000000 |
2 | 20000000 |
3 | 25000000 |
curl --location '0000:3000/disburse' \
--header 'Content-Type: application/json' \
--data '{
"user_id": 2,
"amount": 5000000
}'
{
"user_id": 2,
"request_amount": 5000000,
"balance": 15000000,
"status": "success"
}
id | balance |
---|---|
1 | 10000000 |
2 | 20000000 |
3 | 25000000 |
curl --location '0000:3000/disburse' \
--header 'Content-Type: application/json' \
--data '{
"user_id": 1,
"amount": 20000000
}'
{
"user_id": 1,
"request_amount": 20000000,
"balance": 10000000,
"status": "insufficient balance"
}
Make sure you have installed all the following prerequisites on your development machine:
- go version : 1.19
To clone this repo:
git clone https://github.com/rizanw/disburse-app.git
To build and start the apps:
- build the binaries:
make build
- start the app:
make run
To run unit test
make test
bin/
is directory for compiled binarycmd/
is the main program directoryfiles/
contains app files (including db & config)file/db
contains sqlite db directoryfile/etc/disburse-app
contains app config files
internal/
contains the whole logic of the appinternal/config
is the config of the app, has relation to files directoryinternal/handler
is application logic interface between this app with clientinternal/model
is model business designinternal/repo
is the repositories to fetch/store data of this appinternal/usecase
is main business logic
go.mod
the golang dependencies list