To contribute with this project please refer to Contribution Guidelines.
An API that handles money transfers between user accounts.
- Authentication enpoint that returns a JWT (JSON Web Token).
- Authorization through JWT.
- Transfer endpoint that manages the transfers of funds between two accounts (source and destination).
- Account endpoint that returns a specific account according to the passed id.
This project uses RVM to manage Ruby and Rails/Gems.
You must have PostgreSQL installed and running.
If you already have RVM installed with its wrappers and bash script it should be straight foward, just run:
cd ./ (to the repository folder)
rvm install ruby 2.6.3 (if needed)
gem install bundler -v 2.0.2
bundle install
rails db:create
rails db:migrate
rails db:seed
rails s
This is a Restful API, so it follows it conventions for routes.
Error responses will follow this format:
{
"errors": "[]:string"
}
The primary currency is BRL (Brazilian real).
Using query params it is possible to specify what relationship to include in the response.
Example:
curl -X GET \
http://localhost:3000/accounts/:account_id/?include_user=true \
-H 'Authorization: Bearer :JWT'
Authenticate an user using its email. Returns a JWT with a lifespan of 24hrs.
curl -X POST \
http://localhost:3000/auth/login \
-H 'Content-Type: application/json' \
-d '{
"user": {
"email": "[email protected]"
}
}'
Body format:
{
"user": {
"email": "string"
}
}
Response format:
{
"token": "string:JWT"
}
All the endpoints listed bellow are protected, so it requires the Authorization header set with a valid JWT.
Returns a account.
curl -X GET \
http://localhost:3000/accounts/1 \
-H 'Authorization: Bearer :JWT'
Response format:
{
"account": {
"id": "number",
"balance_cents": "number",
"balance": "formated_balance_value:string"
}
}
- User
Response format:
{
"account": {
"id": "number",
"balance_cents": "number",
"balance":"formated_currency_value:string",
"user": {
"id": "number",
"email": "string",
"first_name": "string",
"last_name": "string"
}
}
}
Create a Transfer and proccess the funds in destination and source accounts. Returns the created transfer with the accounts related included.
curl -X POST \
http://localhost:3000/transfers \
-H 'Authorization: Bearer :JWT' \
-H 'Content-Type: application/json' \
-d '{
"transfer": {
"value": "10.00",
"destination_id": "1",
"source_id": "2"
}
}'
Body format:
- Value format: '00.00'
- where the decimals are separated with dot ('.').
{
"transfer": {
"value": ":value_format:string",
"destination_id": "number",
"source_id": "number"
}
}
Response format:
{
"transfer": {
"id": "number",
"initial_balance_cents": "number",
"value_cents": "number",
"initial_balance": "formated_currency_value:string",
"value": "formated_currency_value:string",
"destination": {
"id": "number",
"balance_cents": "number",
"balance": "formated_currency_value:string"
},
"source": {
"id": "number",
"balance_cents": "number",
"balance": "formated_currency_value:string"
}
}
}
This project uses Rspec as it's testing tool.
To run the entire test suite, run:
cd ./ (to the repository folder)
rspec
You should see something like this:
CreateTransfer
.call
with inexistent destination_id
does not create the transfer
fails
returns inexistent destination account message
with correct arguments
debits the source account
creates the transfer
sets the correct columns on transfer
succeeds
returns the created transfer
returns no erros
credits the destination account
with inexistent destination_id and source_id
fails
returns inexistent message for both
does not create the transfer
with inexistent source_id
fails
returns inexistent source account message
does not create the transfer
with incorrect formatted value
returns incorrect value message
fails
does not create the transfer
If the text from the output is green 💚 means that the test passed and a red 🔴 text means that it failed.
Licensed under the MIT license, see the separate LICENSE file.