Skip to content

Purely functional Scala implementation of REST API for money transfer

Notifications You must be signed in to change notification settings

ilya-murzinov/money-transfer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

money-transfer

Build status: CircleCI

Purely functional Scala implementation of REST API for money transfer between accounts using Finch, Circe, Doobie and Scalatest with Featherbed for testing.

To run simply execute sbt run.

To package executable binary run sbt clean test stage. Executable will be installed in ./target/universal/stage/bin/money-transfer

API root URL: http://localhost:8080/api/

The following methods implemented:

PUT /account

Creates new account, returns account in response.

Example request:

{
  "firstName": "John",
  "lastName": "Smith",
  "amount": 100
}

Example response:

Status: 200
{
  "id": "ed8d39bf-765d-4d56-af5f-5ffa5f9b3264",
  "firstName": "John",
  "lastName": "Smith",
  "amount": 100.0
}

GET /account/$id

Example response:

Status: 200
{
  "id": "ed8d39bf-765d-4d56-af5f-5ffa5f9b3264",
  "firstName": "John",
  "lastName": "Smith",
  "amount": 100.0
}

Possible errors:

  • Account not found:
    Status: 404
    {
      "message": "Account with id 'ed8d39bf-765d-4d56-af5f-5ffa5f9b3264' not found"
    }
    

POST /transaction

Transfers money from one account to another. Returns successful transaction.

Example request:

{
  "fromId": "ed8d39bf-765d-4d56-af5f-5ffa5f9b3264",
  "toId": "9dcc42e7-fde6-477a-bbda-3700c7879a44",
  "amount": 10
}

Example response:

Status: 200
{
  "fromId": "ed8d39bf-765d-4d56-af5f-5ffa5f9b3264",
  "toId": "9dcc42e7-fde6-477a-bbda-3700c7879a44",
  "amount": 10
}

Possible errors:

  • Account not found
    Status: 404
    {
      "message": "Account with id 'ed8d39bf-765d-4d56-af5f-5ffa5f9b3264' not found"
    }
    
  • Can't transfer negative amount of money:
    Status: 400
    {
      "message": "Can't transfer non-positive amount of money"
    }
    
  • Not enough money to transfers:
    Status: 400
    {
      "message": "Account with id 'ed8d39bf-765d-4d56-af5f-5ffa5f9b3264' doesn't have enough money to transfer to account with id '9dcc42e7-fde6-477a-bbda-3700c7879a44'"
    }
    

About

Purely functional Scala implementation of REST API for money transfer

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages