/Borrowers

API Borrowers Services

Primary LanguageJava

Challenge (from Capita) to implement Borrowers API for a Library

Description:

Implement a Rest API in Java to support CRUD operations around a borrower for a Library. These are some scenarios:

  • Search a list of borrowers
  • Search a specific borrower with its full name
  • Add a new borrower to a Library
  • Validate a check data of the borrower details
  • Update an existing borrower
  • Delete an existing borrower
  • etc ...

Response

Create a Spring boot application with a migration tool such as Flyway to generate the schema and to insert the data to a Mysql database.

High technical Architecture overview of the project

Prerequisites

  • Java 17
  • Gradle 8.5
  • WSL2/Ubuntu distro
  • Install Docker, docker-compose in your distro.
  • Set up your environment with the prerequisites and then clone the git project.

Run the project

1. Build project by excluding the test step:

./gradlew clean build -x test

2. Reset all images related to the project

You can use this script to remove all old images generated by your project. If this is the first time you run the project, you don't require to run the script.

./reset.sh

3. Run the project with docker-compose command

docker-compose up -d --no-cache

As this is the first time you run the project, it will pull Mysql and build an image of the application. It will then run all services: db and app. (docker.compose.yml)

4. Check the services running properly

docker-compose ps

5. Check the log file to see what it is going on behind the scene

The log file is generated in the container and mapped with the local:

/logs/borrowers-services.log

If you have any issue, the previous command should show you that your service has stopped unexpectedly due to an issue.

    Name                  Command             State                           Ports
----------------------------------------------------------------------------------------------------------
c_bw_db         docker-entrypoint.sh mysqld   Up       0.0.0.0:3306->3306/tcp,:::3306->3306/tcp, 33060/tcp
c_bw_services   ./entrypoint.sh               Exit 1

In this case, check the log file above and try to troubleshoot the error.

6. Stop and remove all services

docker-compose down

Any change in the code Java requires as usual to build your project. Make sure to run reset.sh which will remove all images. Then, you can start fresh again.

If you don't want to remove Mysql image, just do it manually yourself to remove the image of the app.

docker rmi mehdimik/borrowers:1.0.0-SNAPSHOT