- The project will act as a small money transfer system with a minimalistic API.
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
- 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.
- 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.
- 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
- 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.
- 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
- 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
- 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
- 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 a400
http response is returned, with the body containing the error as a json response.
-
The project is built using
maven
, so a simplemvn clean install
should be enough. -
To run the project just run the resulting jar inside the
target
directory by typingjava -jar money-transfer-service-1.0-SNAPSHOT.jar
-
Note that you should have the newest
maven
version i used3.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 byjooq
maven plugin, so make sure to do that so that the code compiles correctly.
- 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.