Skip to content

RafaZeero/go-pays

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go pays

"Go pays" is a rest API made with Go using GIN that allows users to create accounts and make transactions for your account.

How to run

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 !!

Technologies

Go MySQL PlanetScale

API Endpoints

GET

GetAccounts /accounts
GetAccountsByID /accounts/:id

POST

CreateAccount /accounts
MakeTransaction /accounts/:id/transaction

PATCH

UpdateAccount /accounts

DELETE

DeleteAccount /accounts


GET /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 /accounts/:id

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**)"
}

POST /accounts

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**)"
}

POST /accounts/:id/transaction

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**)"
}

PATCH /accounts/:id

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 /accounts/:id

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**)"
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages