This project is a reactive Spring Boot application for managing authors and their books. It exposes REST APIs for CRUD operations and demonstrates the use of Spring WebFlux, R2DBC, and Flyway for database migrations.
- Java 21 – Programming language
- Spring Boot 3.5.4 – Application framework
- Spring WebFlux – Reactive REST API framework
- R2DBC – Reactive database connectivity
- PostgreSQL – Database
- Flyway – Database migrations
- JUnit 5 & Mockito – Unit testing
- Maven – Build and dependency management
git clone https://github.com/your-org/author-management.git
cd author-management
Ensure PostgreSQL is installed and running. Create a database for the service, for example:
CREATE DATABASE author_db;
Update connection details in src/main/resources/application-qa.yml
:
spring:
r2dbc:
url: r2dbc:postgresql://localhost:5432/author_db
username: your_username
password: your_password
spring:
flyway:
url: jdbc:postgresql://localhost:5432/author_db
user: your_username
password: your_password
locations: classpath:db/migration
Flyway runs migrations automatically on application startup. To run migrations manually:
mvn flyway:migrate
Migration scripts are located in:
src/main/resources/db/migration
Each script should follow the Flyway naming convention, for example:
V1__create_author_table.sql
V2__create_book_table.sql
To run the application with the qa
profile:
mvn spring-boot:run -Dspring-boot.run.profiles=qa
To run all unit tests with the qa
profile:
mvn clean test -Dspring.profiles.active=qa
Tests use Mockito for mocking dependencies and WebTestClient for controller testing.
GET /api/authors
→ Get all authorsGET /api/authors/{id}
→ Get author with booksPOST /api/authors
→ Create new authorPUT /api/authors/{id}
→ Update authorDELETE /api/authors/{id}
→ Delete an authorPOST /api/authors/{id}/books
→ Add book to authorPUT /api/authors/{authorId}/books/{bookId}
→ Update book by authorDELETE /api/authors/{authorId}/books/{bookId}
→ Delete book by authorGET /api/authors/{id}/books
→ Get all books of an author