REST service for library management using Spring Boot, JPA, Spring Validator, PostgreSQL, JUnit and Mockito.
- Java 17
- Spring Boot 3.5.0
- Spring Data JPA
- PostgreSQL
- Docker / Docker Compose
- JUnit 5 / Mockito
- Swagger (OpenAPI)
git clone https://github.com/terletskij/library-management.git
cd library-management
Create a .env file in the root of project
DATABASE_USER=user-name
DATABASE_PASSWORD=user-password
DATABASE_NAME=librarydb
MAX_BORROWED_BOOKS=10
Note
You can customize MAX_BORROWED_BOOKS to set how many books a member is allowed to borrow at one time.
docker-compose up --build
This will:
- Start a PostgreSQL container
- Build and start the Spring Boot application
Swagger UI: http://localhost:8080/swagger-ui/index.html
OpenAPI Docs: http://localhost:8080/v3/api-docs
-
CRUD for Books (/api/v1/books)
-
CRUD for Members (/api/v1/members)
-
Borrow and return books (/api/v1/borrow)
-
Retrieve borrowed books by member ID or name
-
Get list of all currently borrowed book titles
-
Get borrowed book titles with count
-
Validation for input data (name formatting, capital letters)
-
Unit testing for services
You can run all unit tests using:
./mvnw test
If you want to run the application manually:
Make sure PostgreSQL is running
Configure application.properties with your DB credentials
Start the app with:
./mvnw spring-boot:run
- Create project structure
- Configure
PostgreSQLconnection - Provide project running via
docker-compose.yml
- Implement
BookandMemberentity - Add validation for
Bookattributes:name(required, capital letter, min 3 symbols),author(required, two capitalized words, e.g. "Paulo Coelho") - Add validation for
Memberattributes:name(required)
- Add
BookRepository&MemberRepository, both should extendJpaRepository - Implement
BookServicefor BooksCRUDoperations - Implement
BorrowServicefor borrow management - Implement
MemberServicefor Library Members CRUD operations
- Implement basic
CRUDendpoints for bothBookControllerandMemberController
- Retrieve all books borrowed by a specific
member by name - Retrieve all borrowed distinct book
names - Retrieve all borrowed distinct book
namesandamounthow much copy of this book was borrowed
- Cover all scenarios with
unittests for services - Test duplicate book handling
- Test borrow/return logic and limits
- Test deletion restrictions
- Provide endpoints documentation via
OpenAPI/Swagger - Add how-to-run project steps in
README