This is a backend service (API and database) for a generic wallet service. This service contains 2 entities:
- Account
- Payment
Tech Stack: golang, go-kit framework, PostgreSQL, docker
git clone https://github.com/kenanya/fin_coins.git
These are config variables that has been registered. Each of the variable already has a default value, but each value can be replaced according to your configuration.
- PORT
- DB_HOST
- DB_PORT
- DB_USER
- DB_PASSWORD
- DB_NAME
- DB_SCHEMA_NAME
Change your current directory to the project directory.
docker-compose -f docker-compose-local.yml build
docker-compose -f docker-compose-local.yml up
go test .\repository\ -v
go test .\account\ -v
go test .\payment\ -v
go test -v
Ensure to run the previous step (B. How to set up and start the backend server) before run this integration test.
Below are the sample requests and expected responses for each API:
Purpose: Creating account Endpoint: {BASE_URL}/account/v1/account
Param | Value |
---|---|
id | unique id for account |
balance | float/decimal |
currency | currency, such as USD, IDR, etc |
curl --location --request POST '{BASE_URL}/account/v1/account' \
--header 'Content-Type: application/json' \
--data-raw '{
"id": "panda101",
"balance": 2500,
"currency": "USD"
}'
200 Ok
Content-Type: "application/json"
{
"account": {
"id": "panda101",
"balance": 2500,
"currency": "USD",
"created_at": "2022-02-09T13:11:02.604785+07:00",
"updated_at": "2022-02-09T13:11:02.604785+07:00"
}
}
Purpose: Listing all available accounts Endpoint: {BASE_URL}/account/v1/account
Param | Value |
---|---|
curl --location --request GET '{BASE_URL}/account/v1/account' \
--data-raw ''
200 Ok
Content-Type: "application/json"
{
"accounts": [
{
"id": "alice456",
"balance": 2100,
"currency": "USD",
"created_at": "2022-02-09T11:19:40.786259Z",
"updated_at": "2022-02-09T11:49:52.361321Z"
},
{
"id": "panda101",
"balance": 2500,
"currency": "USD",
"created_at": "2022-02-09T13:11:02.604785Z",
"updated_at": "2022-02-09T13:11:02.604785Z"
}
]
}
Purpose: Getting account by account id Endpoint: {BASE_URL}/account/v1/account/{id}
Param | Value |
---|---|
id | account id |
curl --location --request GET '{BASE_URL}/account/v1/account/panda101' \
--data-raw ''
200 OK
Content-Type: "application/json"
{
"account": {
"id": "panda101",
"balance": 2500,
"currency": "USD",
"created_at": "2022-02-09T13:11:02.604785Z",
"updated_at": "2022-02-09T13:11:02.604785Z"
}
}
Purpose: Sending payment from one account to another account that registered in this wallet system Endpoint: {BASE_URL}/payment/v1/payment
Param | Value |
---|---|
account_id | account id of the sender |
amount | amount of money that will be sent |
to_account | account id of the receiver |
curl --location --request POST '{BASE_URL}/payment/v1/payment' \
--header 'Content-Type: application/json' \
--data-raw '{
"account_id": "bob123",
"amount": 50,
"to_account": "alice456"
}'
200 OK
Content-Type: "application/json"
{}
Purpose: Listing all payments Endpoint: {BASE_URL}/account/v1/account
Param | Value |
---|---|
curl --location --request GET '{BASE_URL}/payment/v1/payment' \
--data-raw ''
200 Ok
Content-Type: "application/json"
{
"payments": [
{
"id": "e850688a-ef15-4da6-8486-b7656752c87b",
"account_id": "bob123",
"transaction_id": "21a3ec76-c017-452d-9eb2-c5d2c0ebbca4",
"amount": 50,
"to_account": "alice456",
"from_account": "",
"direction": "outgoing",
"created_at": "2022-02-09T14:15:00.421456Z"
},
{
"id": "9479d132-4553-4ad7-b3b1-978412c88b41",
"account_id": "alice456",
"transaction_id": "21a3ec76-c017-452d-9eb2-c5d2c0ebbca4",
"amount": 50,
"to_account": "",
"from_account": "bob123",
"direction": "incoming",
"created_at": "2022-02-09T14:15:00.457359Z"
}
]
}