Skip to content
This repository has been archived by the owner on Sep 11, 2022. It is now read-only.

A minimalistic sample of a money transfer api made for the Revolut coding challenge.

Notifications You must be signed in to change notification settings

chermehdi/money-transfer-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Money Transfer Service

Description

  • The project will act as a small money transfer system with a minimalistic API.

Technologies used

To build the project we used:

  • Java 11: as our runtime.
  • Spark Java: to serve the api requests.
  • Jooq: to give us a DSL to write type-safe SQL.
  • Google Guice: as our dependency injection framework.
  • Maven: as our build tool

API Description

Create a user

  • METHOD: POST
  • URL: /users
  • BODY:
{
  "firstName": "user1",
  "lastName": "user1",
  "preferredCurrency": "EUR"
}
  • RETURN STATUS: 201 created
{
  "accountId": "1f442fda-b0c4-40a0-b2f8-89dca5e0b2d8"
}
  • RETURN DESCRIPTION: the request will return the id of the newly created account associated with the created user.

List all the users

  • METHOD: GET
  • URL: /users
  • RETURN STATUS: 200 OK
[
  {
    "firstName": "user1",
    "lastName": "user1",
    "balance": 100.0,
    "preferredCurrency": "EUR"
  }
]
  • RETURN DESCRIPTION: the request will return the id of the newly created account associated with the created user.

Add money to an account

  • METHOD: POST
  • URL: /accounts/{account_id}/transactions
  • BODY:
{
  "amount": 200.0,
  "currency": "EUR"
}
  • RETURN STATUS: 200 OK
{
  "amount": 200.0,
  "currency": "EUR",
  "status": "Success"
}
  • RETURN DESCRIPTION: the request will return a view of the updated account balance, with the status of transaction

Transfer money between two accounts

  • METHOD: POST
  • URL: /transfers
  • BODY:
{
  "fromAccountId": "1f442fda-b0c4-40a0-b2f8-89dca5e0b2d8",
  "toAccountId": "1f4212fda-b324-230a-b1f8-89123ae0bsa21",
  "currency": "EUR",
  "amount": 100.0
}
  • RETURN STATUS: 200 OK
{
  "status":"SUCCESS",
  "amount":30,
  "currency":"EUR"
}
  • RETURN DESCRIPTION: returns the status of the performed transfer, or the errors if such operation cannot be performed.

Get all transfers

  • METHOD: GET
  • URL: /transfers
  • RETURN STATUS: 200 OK
{
  "transfers": [
    {
      "fromAccountId": "1f442fda-b0c4-40a0-b2f8-89dca5e0b2d8",
      "toAccountId": "1f4212fda-b324-230a-b1f8-89123ae0bsa21",
      "amount": 100.0,
      "currency": "EUR"
    }
  ]
}
  • RETURN DESCRIPTION: returns the list of all the performed transfers

Get all accounts

  • METHOD: GET
  • URL: /accounts
  • RETURN STATUS: 200 OK
{
  "transfers": [
    {
      "identifier": "e88e3544-6cfe-4e8c-984e-b6826b97d234",
      "balance": 100.0,
      "currency": "EUR"
    }
  ]
}
  • RETURN DESCRIPTION: returns the list of all accounts

Get Account by identifier

  • METHOD: GET
  • URL: /accounts/{account_id}
  • RETURN STATUS: 200 OK
{
  "identifier": "e88e3544-6cfe-4e8c-984e-b6826b97d234",
  "balance": 100.0,
  "currency": "EUR"
}
  • RETURN DESCRIPTION: returns the account identified by account_id

Error case:

  • The API description does not say what's expected if wrong information is entered, because it's quite similar for all the routes, if a lookup for a resources is not found, 404 http response is returned, in case of validation errors or errors related to business logic a 400 http response is returned, with the body containing the error as a json response.

Building and Running

  • The project is built usingmaven, so a simple mvn clean install should be enough.

  • To run the project just run the resulting jar inside the target directory by typing java -jar money-transfer-service-1.0-SNAPSHOT.jar

  • Note that you should have the newest maven version i used 3.6.1 and Java 11 to build the project.

  • If you open the code in your IDE without running mvn install it won't compile, due to some models that needs to be generated by jooq maven plugin, so make sure to do that so that the code compiles correctly.

Transfer consistency

  • If two or more transfers used the same accounts, without proper synchronization, we might have problems, and inconsistent results. to prevent that, i used record locking to lock some record while being updated and guarantee Isolation.

About

A minimalistic sample of a money transfer api made for the Revolut coding challenge.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published