Skip to content

RESTful API Lab 8

Lab#8 Loans MicroService


In this lab we will create a loans microservice, similar to the accounts service.

Project Layout
Figure 1: Project Layout

Schema.sql, LoansConstants, ILoansService and LoansServiceImpl and LoansMapper files are given. Use port 8090 in the .yml file.


Creating a Loan

First create a customer as before using the accounts microservice.

Create a customer
Fig. 2 Create a customer

Now using the same mobile number create a loan. The mobile number supplied must be 10 digits long. A loan cannot already exist for the customer with given mobile number.

Create a loan - Mobile number too short
Fig. 3 Create a loan - Mobile number too short

Create a loan -  Loan already exists for customer
Fig. 4 Create a loan - Loan already exists for customer

Loan created success
Fig. 5 Loan created success.

Creating a loan – code in LoansServiceImpl
Fig. 6 Creating a loan – code in LoansServiceImpl

The loan is create using default values as shown and the number is generated as shown


Fetch loan details

Fetching loan details - success
Fig. 7 Fetching loan details - success

Fetching loan - mobile number not 10 digits
Fig. 8 Fetching loan - mobile number not 10 digits

Fetching loan – no loan for given mobile number
Fig. 9 Fetching loan – no loan for given mobile number


Update Loan details

Updating loan –loan details updated successfully
Fig. 10 Updating loan –loan details updated successfully

Fetch updated values –loan details updated
Fig. 11 Fetch updated values –loan details updated

Updating loan –validation errors in data
Fig. 12 Updating loan –validation errors in data

See LoansDto for error example

Handling errors in LoansDto
Fig. 13 Handling errors in LoansDto

Update loan - Mobile number not 10 digits
Fig. 14 Update loan - Mobile number not 10 digits


DELETE Mapping

Deleting a loan
Fig. 15 Deleting a loan

Deleting a loan – mobile number too short
Fig. 16 Deleting a loan – mobile number too short

Deleting a loan – loan with mobile number not found
Fig. 17 Deleting a loan – loan with mobile number not found