This service is used to manage loan application from customers and collect emi from customers
Import file Aspire-mini-loan-service.postman_collection.json
into Postman
Use Intellij Idea Ultimate
Only works with JAVA 17
- Allow customer to request for new Loan
- Allow admin to view and approve/decline Loan
- Allow customer to Submit weekly loan repayments
- Allow customer to view upcoming loan repayment(installment)
- Generate repayments with PENDING state
- Policy to make sure customer can view his own loan only
- Policy to verify amount is greater than or equal to scheudled payment
- Loan statuc become PAID when all amount is paid back
- Appropriate exception and error code with message for wrong or not allowed requests
- Authentication before login
- Admin can see all users loan
- Every rest api has Triple authentication
- First it authenticates the user, then it checks if user belongs to the appropriate group, third, if user has the access
- The new repayment will be generated only when last repayment is paid
- This is, to dynamically allow customer to pay any amount greater than installment.
- Using this, customer can close the loan in one go also
- The user authentication details are saved in-memory in
SecurityConfig.java
for prototyping - To switch to different user, simply update the
Basic Auth
details fromuser1
touser2
in postman
- user1 : userpass : CUSTOMER
- user2 : userpass : CUSTOMER
- admin1 : adminpass : ADMIN
build : ./gradlew clean build
test : ./gradlew clean test
run : ./gradlew clean run
- To switch to different user, simply update the
Basic Auth
details fromuser1
touser2
in postman
API | Type | Description | Auth User |
---|---|---|---|
/api/v1/loan |
get | Get All loans by the authenticated user | Customer |
/api/v1/loan |
post | Apply for new loan | Customer |
/api/v1/loan/plan |
get | Get upcoming Installment of a loan | Customer |
/api/v1/loan/plans |
get | Get All Installment(past+upcoming) of a loan | CUSTOMER |
/api/v1/loan/plan |
patch | Pay EMI | CUSTOMER |
/api/v1/admin/loan |
get | get All Loans of all Users | ADMIN |
/api/v1/admin/loan |
patch | Approve or reject loan | ADMIN |
/api/v1/admin/loan/plans |
get | get all past and upcoming installment of a loan | ADMIN |
/api/v1/admin/loan |
patch | Pay EMI | ADMIN |
- HttpStatus.FORBIDDEN : 403 -> when customer1 request for loan data of customer 2
- HttpStatus.NOT_FOUND : 404 -> when loanId doesn't exist
- HttpStatus.NOT_ACCEPTABLE : 406 -> when loan status is not appropriate
Command to run all the tests(20+ tests) : ./gradlew clean test
- AdminLoanControllerApiTest.java
- CustomerLoanControllerApiTest.java
- LoanServiceUTest.java
- InstallmentRepositoryITest.java
- LoanRepositoryITest.java
type : h2
in-memory embedded database
Note : First I used postgres
, but to make the application run simpler, migrated to h2
embedded db
loan
column | Type | Description |
---|---|---|
id |
UUID | Loan ID(PK) |
customer_id |
varchar | ID of Customer |
amount |
float8 | Loan Amount |
loan_term |
int4 | Loan Term |
installment_amount |
float8 | Installment Amount |
pending_amount |
float8 | Total Pending Amount |
pending_terms |
int4 | Pending Terms |
status |
int2 | Status of Loan |
loan_applied_date |
date | Loan Applied Date |
loan_approved_date |
date | Loan Approved Date |
updated_by |
varchar | Loan Approved By |
installment
column | Type | Description |
---|---|---|
id |
UUID | Loan ID(PK) |
actual_payment_date |
varchar | ID of Customer |
loan_id |
float8 | Loan Amount |
pending_amount |
int4 | Loan Term |
received_amount |
float8 | Installment Amount |
scheduled_payment_date |
float8 | Total Pending Amount |
payment_status |
int4 | Pending Terms |
term_no |
int2 | Status of Loan |
- Postman Collection
- Test Cases -> Service Unit Test, Controller API test, Repository Integration Test
- Error Codes With Proper Message -> Appropriate mapping of exception to error codes
- All in one application with DB integration
- Docker support
- Authentication, Authorisation(grp based) and access policy