Steps to run the application from IDE:
- Import project into any IDE like Intellij using pom.xml
- Run App from Intellij Configuration straight away
- (Or) Go to MoneyTransferApplication File -> Right Click -> Run
From command line:
- Build the project using pom.xml - > mvn clean install
- Run the application -> java -jar target/revolut-1.0-SNAPSHOT.jar
Note: Application runs on port 4567 by default.
- Java 8
- Spark Java (for REST)
- GSON (for JSON handling)
- Junit 5 unit tests
- Postman Client (for API test suite)
Command | HTTP Method | Description |
---|---|---|
/accounts |
POST | Creates New Account (Initial Balance should be provided as input) |
/accounts/:id |
GET | Fetches an account of the ID passed |
/accounts |
GET | Fetches all the accounts |
/accounts/:id/credits |
GET | Fetches all the credits of an account of the ID passed |
/accounts/:id/debits |
GET | Fetches all the debits of an account of the ID passed |
/transactions |
POST | Creates New Transaction (From Account ID, To Account ID, Transaction Amount are to be provided in the input payload) |
/transactions/:id |
GET | Fetches a transaction of the ID passed |
/transactions |
GET | Fetches all the transactions |
{
"balance":200.45
}
{
"id": 3,
"balance": 200.45,
"credits": [],
"debits": []
}
{
"fromAccountId" :1,
"toAccountId" :2,
"amount": 124.25
}
{
"id": 1,
"amount": 124.25,
"fromAccountId": 1,
"toAccountId": 2,
"timestamp": "Jan 11, 2020, 12:58:21 PM"
}
PS: API test suite is checked into this repo inside resources folder which can be imported onto POSTMAN.
- There's one main class which initiates the REST API and its controllers.
- Both account and transaction have seperate controller classes for handlings its corresponding routes
- Input validations are handled in a common validation utility and applied wherever necessary in controllers.
- Service classes each having its own for handling specific operations has the ID generated and automatically assigned. In-memory data structures are used for storage.
- A custom exception handler is registered during API initialization and sets error code to response based on the type of exception.
- A new custom exception called "BusinessException" is created for application errors.
- GSON is used for request parsing and response handling
- For concurrency, reentrant read write locks are used at the time of amount transfer.