Design and implement a RESTful API (including data model and the backing implementation) for money transfers between accounts.
Backend Test
Design and implement a RESTful API (including data model and the backing implementation) for money transfers between accounts. Explicit requirements:
- You can use Java, Scala or Kotlin.
- Keep it simple and to the point (e.g. no need to implement any authentication).
- Assume the API is invoked by multiple systems and services on behalf of end users.
- You can use frameworks/libraries if you like (except Spring), but don't forget about requirement #2 โ keep it simple and avoid heavy frameworks.
- The datastore should run in-memory for the sake of this test.
- The final result should be executable as a standalone program (should not require a pre-installed container/server).
- Demonstrate with tests that the API works as expected. Implicit requirements:
- The code produced by you is expected to be of high quality.
- There are no detailed requirements, use common sense. Please put your work on github or bitbucket.
==========================================================================================
##how to build:
mvn clean package
##how to run:
cd target
java -jar revolut-1.0-SNAPSHOT.jar 8081
##what will be displayed:
Server is listening on port 8081
##API
###Example:
curl -X POST -i http://localhost:8081/transfer --data '{"from":"CashMachine","to":"Tanya","amount":"20"}'
#####what will be returned to the client:
{
"status": "TRANSFERRED"
}
#####what will you see in the default system log:
New client connected
No recipient found. Creating...
CashMachine 980
Tanya 20
###Next example:
curl -X POST -i http://localhost:8081/transfer --data '{"from":"CashMachine","to":"Roman","amount":"200"}'
{ "status": "TRANSFERRED" }
New client connected
No recipient found. Creating...
CashMachine 780
Tanya 20
Roman 200
###Next example:
curl -X POST -i http://localhost:8081/transfer --data '{"from":"Roman","to":"Tanya","amount":"100"}'
{ "status": "TRANSFERRED" }
New client connected
CashMachine 780
Tanya 120
Roman 100
###Example:
curl -X POST -i http://localhost:8081/transfer --data '{"from":"Roman","to":"Tanya","amount":"-100"}'
{
"status": "FAILED"
}
#####what will you see in the default system log:
New client connected Server exception: null com.drastic.exception.NegativeAmountException at com.drastic.transfer.MoneyTransfer.transfer(MoneyTransfer.java:34) at com.drastic.transfer.TransferMaker.makeTransfer(TransferMaker.java:20) at com.drastic.server.Request.run(Request.java:42) at java.lang.Thread.run(Thread.java:748)
###Next example:
curl -X POST -i http://localhost:8081/transfer --data '{"from":"Roman","to":"Tanya","amount":"500"}'
{ "status": "FAILED" }
#####what will you see in the default system log:
New client connected com.drastic.exception.InsufficientFundsException Server exception: null at com.drastic.transfer.MoneyTransfer.transfer(MoneyTransfer.java:36) at com.drastic.transfer.TransferMaker.makeTransfer(TransferMaker.java:20) at com.drastic.server.Request.run(Request.java:42) at java.lang.Thread.run(Thread.java:748)