A sample loan app for pezesha technical test.
Bulit with spring-boot, Mysql, JDK 17
- MySQL running locally on port 3306.
- JDK version 17.
- A Rest client like postman or insomnia to test the rest endpoint.
- git if using unix based machine or git-bash if on windows.
- maven version 3.8.7
git clone https://github.com/chess254/loans.git
NB: Make sure the database is running on the host and port configured above before continuing to the following steps and localhost port 8080 is open.
spring.datasource.url=jdbc:mysql://<host>:<port>/<database_name>
spring.datasource.username=<database_username>
spring.datasource.password=<database_user_password>
<host> (the url in which the mysql database is running locally)
<port> (port in which db is listening)
<database_username> ( username to the database)
<database_user_password (password for the database)>
cd loans
mvn clean
(on unix based) or .\mvnw clean
(on windows)
then
mvn install
() or .\mvnw install
to add the projects dependencies using maven and run the tests.
Run mvn spring-boot:run
(unix based ) or .\mvnw spring-boot:run
(on windows)
This will seed the database with initial dummy data from file loans/src/main/resources/schema.sql
and start the application.
POST
localhost:8080/accounts
sample JSON payload: deposit Must be positive
{"deposit": 2222}
sample JSON Response
{
"id": 6,
"balance": 2222
}
GET
localhost:8080/accounts
sample JSON Response
[
{
"id": 1,
"balance": 1000.00
},
{
"id": 2,
"balance": 500.00
},
{
"id": 3,
"balance": 2000.00
},
{
"id": 4,
"balance": 300.00
},
{
"id": 5,
"balance": 1500.00
},
{
"id": 6,
"balance": 2222.00
}
]
GET
localhost:8080/accounts/{id}
sample JSON Response
{
"id": 6,
"balance": 2222.00
}
POST
localhost:8080/transfers
The fields sourceAccountId & destinationAccountId must be valid accounts in the database and amount should be greater than zero. source account must have sufficient balance fot transfer to be successful.
sample JSON payload:
{
"sourceAccountId" : 1,
"destinationAccountId" : 5,
"amount" : 500
}
sample JSON response:
{
"id": 1,
"sourceAccount": {
"id": 5,
"balance": 1000.00
},
"destinationAccount": {
"id": 1,
"balance": 1500.00
},
"amount": 500,
"timestamp": "2023-04-11T06:43:50.8824894"
}
In a web browser navigate to the http://localhost:8080/form to display form that takes in input values. Fill in the form and submit to display a table showing the breakdown of the loan repayments over the loan term.
POST
localhost:8080/calculate
sample JSON payload: Must be positive. The value for repaymentFrequency is;
0 for monthly,
1 for bi monthly
or 2 for Weekly.
{
"loanAmount" :100,
"loanTermMonths" : 2,
"interestRate" : 10,
"repaymentFrequency" : 1
}
sample JSON response:
{
"loanAmount": 100.0,
"loanTermMonths": 2,
"interestRate": 10.0,
"repaymentFrequency": "BIMONTHLY",
"repayments": [
{
"month": 1,
"paymentAmount": 51.25,
"principal": 49.59,
"interest": 1.67,
"balance": 50.41
},
{
"month": 2,
"paymentAmount": 51.25,
"principal": 50.41,
"interest": 0.84,
"balance": 0.0
}
],
"totalPaymentAmount": 102.5,
"totalPrincipal": 100.0,
"totalInterest": 2.51
}