项目作者: AlexandruValeanu

项目描述 :
Money transfer RESTful API written in Java using Vert.x
高级语言: Java
项目地址: git://github.com/AlexandruValeanu/MoneyTransfer.git
创建时间: 2019-09-01T20:34:48Z
项目社区:https://github.com/AlexandruValeanu/MoneyTransfer

开源协议:

下载


MoneyTransfer

RESTful API for money transfers between accounts.

  • Written in Java
  • Simple and to the point
  • Written using Vert.x and without any heavy frameworks
  • In-memory datastore
  • Standalone program
  • Unit and integration tests

Tech stack

How to build the application

  1. mvn clean package

How to run the application

The application runs be default on port 8080. After you built it, you can run it by using

  1. java -jar target/MoneyTransfer-1.0-SNAPSHOT-fat.jar

If you cannot built it you can run it using the fat jar provided in the jars folder.

If you want to run multiple instances use

  1. java -jar target/MoneyTransfer-1.0-SNAPSHOT-fat.jar -instances 4

If you want to run using a different configuration (for example on a different port) use

  1. java -jar target/MoneyTransfer-1.0-SNAPSHOT-fat.jar -conf src/main/conf/config.json

How to run the tests

Unit tests:

  1. mvn clean test

All tests:

  1. mvn clean verify

How to use the application

Accounts

Create an account

  1. POST http://localhost:8080/accounts
  2. {"user":"alex", "currency":"USD", "balance":100}

Response:

  1. {"id":"56d3b507-9175-4cd6-b2bb-3a83613dd8bd","user":"alex","currency":"USD","balance":100}

Get an account

  1. GET http://localhost:8080/accounts/56d3b507-9175-4cd6-b2bb-3a83613dd8bd

Response:

  1. {"id":"56d3b507-9175-4cd6-b2bb-3a83613dd8bd","user":"alex","currency":"USD","balance":100}

Get all accounts

  1. GET http://localhost:8080/accounts

Response:

  1. [{"id":"56d3b507-9175-4cd6-b2bb-3a83613dd8bd","user":"alex","currency":"USD","balance":100}]

Update an account

  1. PUT http://localhost:8080/accounts/56d3b507-9175-4cd6-b2bb-3a83613dd8bd
  2. {"balance":10}

Response:

  1. {"id":"56d3b507-9175-4cd6-b2bb-3a83613dd8bd","user":"alex","currency":"USD","balance":10}

Delete an account

  1. DELETE http://localhost:8080/accounts/56d3b507-9175-4cd6-b2bb-3a83613dd8bd

Transfers

Create a transfer (and execute it)

  1. POST http://localhost:8080/transfers
  2. {"source-id":"56d3b507-9175-4cd6-b2bb-3a83613dd8bd", "dest-id":"26df4b98-ac89-418f-b383-a9d5df4024bb", "amount":10}

Response:

  1. {"id":"63686614-fd19-409a-9712-2bc2dfa87bfd","source":{"id":"56d3b507-9175-4cd6-b2bb-3a83613dd8bd","user":"alex","currency":"USD","balance":90},"destination":{"id":"26df4b98-ac89-418f-b383-a9d5df4024bb","user":"ben","currency":"USD","balance":20},"amount":10}

Note that it is not allowed to transfer money from one account to itself, to transfer money between accounts that do not have the same currency or to transfer a non-positive amount (less than or equal to zero) amount of money.
Also note that the transfer is executed right after it is created with no confirmation from the user.

Get a transfer

  1. GET http://localhost:8080/transfers/63686614-fd19-409a-9712-2bc2dfa87bfd

Response:

  1. {"id":"63686614-fd19-409a-9712-2bc2dfa87bfd","source":{"id":"56d3b507-9175-4cd6-b2bb-3a83613dd8bd","user":"alex","currency":"USD","balance":90},"destination":{"id":"26df4b98-ac89-418f-b383-a9d5df4024bb","user":"ben","currency":"USD","balance":20},"amount":10}

Get all transfers

  1. GET http://localhost:8080/transfers

Response:

  1. [{"id":"63686614-fd19-409a-9712-2bc2dfa87bfd","source":{"id":"56d3b507-9175-4cd6-b2bb-3a83613dd8bd","user":"alex","currency":"USD","balance":90},"destination":{"id":"26df4b98-ac89-418f-b383-a9d5df4024bb","user":"ben","currency":"USD","balance":20},"amount":10}]

Note that is is not possible to delete or update transfers (design choice).