This simple web service is created for the completion of Credibook Technical Assesment.
All datas in this web service saved in:
- MySQL; used as the main database in this service
This endpoint used for user login
[POST] /login
{
"username": "admin",
"password": "admin"
}
This endpoint used for getting all user list. This API can only be accessed by Admin
[GET] /users
User auth for this endpoint is bearer token using token got from the login API
{
"total_records": 3,
"data": [
{
"id": 1,
"created_at": "2021-06-11T15:49:19Z",
"updated_at": "2021-06-11T15:49:19Z",
"deleted_at": null,
"username": "admin",
"is_admin": true
}
],
"current_page": 1,
"total_pages": 1
}
This endpoint used for creating new user
[GET] /user
{
"username": "User",
"password": "My Pass"
}
{
"New user created"
}
This endpoint used to get all transactions saved in the database.
[GET] /transaction
User auth for this endpoint is bearer token using token got from the login API
This API provided 3 filters in the query param :
- page
- perpage
- type; will show transaction with types as in the filter
- min_amount; will show transaction in with amount higher than or equal as in the filter
- max_amount; will show transaction in with amount lower than or equal as in the filter
- order_by; can be used to sort the data, please add ' DESC' if it's sorted descending
{
"total_records": 3,
"data": [
{
"id": 1,
"created_at": "2021-06-14T15:21:42Z",
"updated_at": "2021-06-14T15:21:42Z",
"deleted_at": null,
"user_id": 2,
"amount": 100000,
"notes": "Kulakan",
"type": "expense"
},
{
"id": 2,
"created_at": "2021-06-14T15:22:17Z",
"updated_at": "2021-06-14T15:22:17Z",
"deleted_at": null,
"user_id": 3,
"amount": 100000,
"notes": "Hasil penjualan",
"type": "income"
}
],
"current_page": 1,
"total_pages": 1
}
This endpoint used to create new transaction and save it to the database.
[POST] /transaction
User auth for this endpoint is bearer token using token got from the login API
{
"amount": 10000, //required
"notes": "Groceries",
"type": "expense"
}
{
"id": 4,
"created_at": "2021-06-14T23:18:14.65788+07:00",
"updated_at": "2021-06-14T23:18:14.65788+07:00",
"deleted_at": null,
"user_id": 2,
"amount": 10000,
"notes": "Groceries",
"type": "expense"
}
This endpoint used to update existing transaction and save it to the database.
[PUT] /transaction/:id
User auth for this endpoint is bearer token using token got from the login API
{
"amount": 150000, //required
"notes": "Kulakan",
"type": "Expense"
}
{
"id": 4,
"created_at": "2021-06-14T23:18:14.65788+07:00",
"updated_at": "2021-06-14T23:18:14.65788+07:00",
"deleted_at": null,
"user_id": 2,
"amount": 150000,
"notes": "Kulakan",
"type": "expense"
}
This endpoint used to delete transaction and save it to the database.
[DELETE] /transaction/:id
User auth for this endpoint is bearer token using token got from the login API
"transaction has deleted successfully"
In this service, there's testing provided. To do the testing, you can use command below:
go test ./... -coverprofile=coverage.out