The goal of this project is provide a transfer API between internal accounts of a digital bank.
make build
make run
make test
-
Method:
POST
-
URL:
/accounts
-
Body:
{ "name": "account-test", "cpf": "97014963023", "secret": "u69UFv$*ETH4", "balance": 100 }
-
Responses:
- Success:
- Status code:
201 - Created
- Example body:
{ "account_id": 53 }
- Status code:
- Errors:
- Request with invalid syntax
- Status code:
400 - Bad Request
- Example body:
{ "error": "secret must be at least 8 characters long" }
- Status code:
- Request with CPF already registered
- Status code:
409 - Conflict
- Example body:
{ "error": "CPF already exists" }
- Status code:
- Internal Server Error
- Status code:
500 - Internal Server Error
- Status code:
- Request with invalid syntax
- Success:
- Method:
GET
- URL:
/accounts
- Responses:
- Success:
- Status code:
200 - OK
- Example body:
[ { "id": 53, "name": "account-test", "cpf": "97014963023", "secret": "$2a$10$L61LEOytm.hUNSeq897S0eBhPwx14hMogi9wZ7EsHCsK115e2Oh7G", "balance": 100, "created_at": "2022-07-24T18:25:20.21256-03:00" } ]
- Status code:
- Errors:
- Internal Server Error
- Status code:
500 - Internal Server Error
- Status code:
- Internal Server Error
- Success:
- Method:
GET
- URL:
/accounts/{account_id}/balance
- Responses:
- Success:
- Status code:
200 - OK
- Example body:
{ "balance": 100 }
- Status code:
- Errors:
- Account not fount
- Status code:
404 - Not Found
- Example body:
{ "error": "record not found" }
- Status code:
- Internal Server Error
- Status code:
500 - Internal Server Error
- Status code:
- Account not fount
- Success:
- Method:
POST
- URL:
/login
- Body:
{ "cpf": "97014963023", "secret": "u69UFv$*ETH4" }
- Responses:
- Success:
- Status code:
200 - OK
- Example body:
{ "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50X2lkIjo1MiwiZXhwIjoxNjU5MjI2MzkyfQ.xdoh-98tbj04-aYp7AtIiucI3YKvWZ5DvjvMoj9FZEo" }
- Status code:
- Errors:
- Account not fount
- Status code:
404 - Not Found
- Example body:
{ "error": "account not found" }
- Status code:
- Unauthorized login
- Status code:
401 - Unauthorized
- Status code:
- Request with invalid syntax
- Status code:
400 - Bad Request
- Status code:
- Internal Server Error
- Status code:
500 - Internal Server Error
- Status code:
- Account not fount
- Success:
- Method:
POST
- URL:
/transfers
- Authorization:
Bearer Token
- Body:
{ "account_destination_id": 54, "amount": 50 }
- Responses:
- Success:
- Status code:
200 - OK
- Example body:
{ "transaction_id": 1 }
- Status code:
- Errors:
- Insufficient balance for transfer
- Status code:
412 - Precondition Failed
- Example body:
{ "error": "insufficient balance for transfer" }
- Status code:
- Unauthorized user
- Status code:
401 - Unauthorized
- Status code:
- Request with invalid syntax
- Status code:
400 - Bad Request
- Status code:
- Internal Server Error
- Status code:
500 - Internal Server Error
- Status code:
- Insufficient balance for transfer
- Success:
- Method:
GET
- URL:
/transfers
- Responses:
- Success:
- Status code:
200 - OK
- Example body:
[ { "id": 1, "account_origin_id": 53, "account_destination_id": 54, "amount": 50, "created_at": "2022-07-24T18:25:20.21256-03:00" } ]
- Status code:
- Errors:
- Unauthorized user
- Status code:
401 - Unauthorized
- Status code:
- Internal Server Error
- Status code:
500 - Internal Server Error
- Status code:
- Unauthorized user
- Success:
-
name
,cpf
, andsecret
are requiredcpf
must contain 11 characterssecret
must contain at least 8 characterssecret
must be saved as hash- the default
balance
amount is 0 - only one account per CPF
-
cpf
andsecret
are required- returns the token to be used in authenticated routes
- the generated token is valid for 1 hour
-
account_destination_id
andamount
are required- use bearer token authentication
- the transfer amount must be greater than 0 and the account balance must be >= the amount to be transferred