"Go pays" is a rest API made with Go using GIN that allows users to create accounts and make transactions for your account.
You can run with:
go run main.go
If you wish to run locally, you may need to add values to your local environment variables (.env), such as these in the .env.example:
PORT=
DB_USER=
DB_PASSWORD=
DB_NAME=
DB_ADDRESS=
And also you will need a local mySQL db running. You can use the main.sql file in /db/main.sql
to create your go_pays_db !!
GetAccounts
/accounts
GetAccountsByID
/accounts/:id
CreateAccount
/accounts
MakeTransaction
/accounts/:id/transaction
UpdateAccount
/accounts
DeleteAccount
/accounts
Get all users accounts in the DB.
See implementation here.
Response
// On success fetching accounts:
[
{
"id": 1,
"name": "Rafa",
"balance": 15000.99,
"createdAt": "2023-09-01T14:20:19Z",
"updatedAt": "2023-09-01T14:20:19Z"
},
{
"id": 2,
"name": "Rayssa",
"balance": 5000.23,
"createdAt": "2023-09-01T14:20:23Z",
"updatedAt": "2023-09-01T14:20:23Z"
}
]
// On error:
{
"error" : "(**error message**)"
}
Get one account by id.
See implementation here.
Response
// On success:
{
"data": {
"account": {
"id": 9,
"name": "Riquinho muito rico",
"balance": 8000000,
"createdAt": "2023-08-31T13:26:02Z",
"updatedAt": "2023-09-01T13:39:57Z"
}
},
"message": "Account found",
"success": true
}
// On error:
// * User not found
{
"error" : "User not found or does not exists"
}
// * Others
{
"error" : "(**error message**)"
}
Create a new account.
See implementation here.
Parameters
Name | Required | Type | Description |
---|---|---|---|
name |
required | string | Name of the account owner |
balance |
required | number (float64) | Initial balance value in the account |
Response
// On success:
{
"data": {
"balance": 991299349956.78,
"id": 48,
"name": "Riquinho rico"
},
"message": "Account created",
"success": true
}
// On error:
{
"error": "(**error message**)"
}
Make a transaction in an account. Can be a deposit or withdrawl.
See implementation here.
Parameters
Name | Required | Type | Description |
---|---|---|---|
amount |
required | number (float64) | The amount of money to be deposit or withdrawl in the transaction |
transaction_type |
required | string ("deposit" or "withdrawl") | Type of transaction, if it is a deposit , the amount will be added to the current balance, if it is a withdrawl , the amount will be subtracted from the current balance |
Response
// On success:
{
"data": {
"account_id": 1,
"amount": 196.01,
"new_balance": 9039.86
},
"message": "Transaction successful",
"success": true
}
// On error:
{
"error": "(**error message**)"
}
Update account owner's name.
See implementation here.
Parameters
Name | Required | Type | Description |
---|---|---|---|
name |
required | string | Name of the account owner |
Response
// On success:
{
"data": {
"account_name": "Nami"
},
"message": "Account updated",
"success": true
}
// On error:
{
"error": "(**error message**)"
}
Delete account.
See implementation here.
Response
// On success:
{
"message": "Account deleted",
"success": true
}
// On error:
// * User not found or not exists
{
"error": "User not found or does not exists"
}
// * Other
{
"error": "(**error message**)"
}