This repository contains a simple library domain model that is used in two different runtimes:
- A Spring Boot REST API backed by MySQL for storing and retrieving books.
- An interactive console program that simulates borrowing rules in a small library.
Both runtimes share the same Maven project and are launched from the Main class with different command line arguments.
- Java 17 (matching the version declared in
pom.xml). - Maven 3.9+ (the bundled
mvnwwrapper works out-of-the-box). - Docker & Docker Compose (only required if you want to run the REST API locally with MySQL).
./mvnw clean package -DskipTestsThe build produces target/groupassignment-1.0-snapshot.jar, which can be used to launch either runtime described below.
-
Start the database and (optionally) Adminer for inspecting data:
docker compose up -d
This spins up MySQL on
localhost:3306using the credentials insrc/main/resources/application.properties(jensen/devops25). Adminer becomes available at http://localhost:8081. -
Launch the application in API mode:
java -jar target/groupassignment-1.0-snapshot.jar 1
The API listens on
http://localhost:8080and exposes the following endpoints:GET /books– list all persisted books.POST /books– add a new book. Example request:curl -X POST http://localhost:8080/books \ -H "Content-Type: application/json" \ -d '{"name": "The Hobbit", "genre": "Fantasy"}'
A helper script,
books_api.sh, demonstrates how to create a couple of records and fetch them back:./books_api.sh
The console option showcases the same domain logic in a text UI where you can borrow, return, and extend loans interactively.
java -jar target/groupassignment-1.0-snapshot.jar 2You will be prompted with single-letter commands:
B– borrow a book from the in-memory stock list.R– return a borrowed book and see any late fees owed.L– list the books you currently have on loan.A/G– list borrowed books filtered by author or genre.E– extend a loan (counts as your borrow action for the day).Q– quit the program.
The program advances the simulated day after each action, which is important for enforcing the borrowing limits that the accompanying tests describe.
Execute the JUnit 5 suite with:
./mvnw testThe tests document the intended borrowing rules (daily borrowing limit, overdue fees, etc.) even where implementations are still evolving.
src/main/java/dev/jensendev25/groupassignment/springboot– Spring Boot REST API components (entity, repository, service, controller).src/main/java/dev/jensendev25/groupassignment/junit– Domain classes used by the console program and unit tests.src/main/resources/application.properties– Database configuration for the API runtime.books_api.sh– Sample cURL script for interacting with the REST endpoints.docker-compose.yml– Local MySQL + Adminer stack compatible with the default application properties.
- Ensure MySQL is running before starting the REST API; connection failures will appear on startup otherwise.
- If ports 8080, 8081, or 3306 are already in use, adjust them in
docker-compose.ymlandapplication.propertiesaccordingly. - The console application keeps all state in memory; restart it to reset inventory and borrowing history.