Loan Calculator is a Java-based backend project that handles loan calculations based on user input from the Loan Calculator frontend application. It exposes RESTful APIs for receiving loan details, performing calculations, and providing Equated Monthly Instalment (EMI) information.
(EMI) is getting calculated based on below formula
- βPβ is the loan amount
- βNβ is tenure in months
- βRβ is the monthly interest rate.
The project follows the Maven standard directory structure. Key components include:
src/main/java
: Contains the Java source code.src/main/resources
: Contains application properties and configurations.src/test
: Contains test classes.
To run the project locally, follow these steps:
- Ensure that Java 17 is installed on your machine. You can download it from here.
- Clone this repository:
git clone https://github.com/MURATKAYMAZ56/loan_calculator-backend.git
- Navigate to the project directory:
cd loan_calculator-backend
- Build the project:
./mvnw clean install
- Run the application:
./mvnw spring-boot:run
- The backend application will be accesiable at
http://localhost:8080
Loan Calculate backend is designed to work seamlessly with the Loan Calculate frontend React application. The integration is achieved through RESTful APIs. The frontend sends loan details to backend, and backend responds with calculated EMI information.
You can either run frontend project by following its configuration steps or use postman as below to calculate emi.
You can use Postman to make API calls to the backend. Follow these steps:
-
Open Postman and create a new request.
-
Set the request type to POST.
-
Enter the API endpoint: http://localhost:8080/api/loans
-
Set the request headers:
Content-Type: application/json
-
In the request body, provide a JSON payload with loan details. For example:
{
"amount": 1000,
"instalment": 11,
"interestRate": 2.4,
"email": "[email protected]"
}
- Click the "Send" button to make the API call. Then you should see api response as below.
{
"emi": 231.11
}
- Review the response in H2 console (See below for H2 console) to see the calculated EMI information.
The Loan Calculator backend uses an H2 in-memory database, and you can access the H2 Console to view and query the data.
- Open your browser and go to
http://localhost:8080/h2-console
. - In the login page, set the following values:
JDBC URL: jdbc:h2:mem:testdb
User Name: sa
Password: pwd
3.Click the "Connect" button.
4. You will be redirected to the H2 Console. Here, you can view and execute SQL queries against the in-memory database.
5. To see data Click on LOAN_ENTITY
table and run below script
SELECT * FROM LOAN_ENTITY
To run tests, execute the following command:
./mvnw test