Bootiful Aggregated Book Service is a Spring Boot application that demonstrates the aggregation of paginated results from two different tables, BookA
and BookB
. The application provides a single endpoint to fetch combined paginated results from both tables, ensuring consistent and accurate pagination.
- Aggregates data from two separate tables within the same application.
- Supports pagination to display a specified number of records per page.
- Ensures efficient data fetching and aggregation.
- Simplifies the aggregation logic by using dynamic offsets.
- Java 21 or higher
- Gradle
- H2 (or any other relational database)
-
Clone the repository:
git clone https://github.com/anishpanthi/bootiful-aggregator.git cd bootiful-aggregator
-
Configure the database:
This application uses H2 In-Memory database, so you can leave the database configuration as it is in the
application.yml
file If you want to use your own database like PostgreSQL, you can configure it in theapplication.yml
file:spring: datasource: url: jdbc:postgresql://localhost:5432/your-database username: your-username password: your-password driver-class-name: org.postgresql.Driver initialization-mode: always jpa: hibernate: ddl-auto: update defer-datasource-initialization: true
Ensure that
schema.sql
anddata.sql
are placed in thesrc/main/resources
directory. Sample is provided in the repository. -
Build the application:
./gradlew build
-
Run the application:
./gradlew bootRun
Once the application is running, you can access the aggregated books endpoint to fetch paginated results.
To fetch the first page with 5 records:
GET http://localhost:8080/aggregator/api/books?page=0&size=5
{
"content": [
{
"id": 1,
"title": "Book A1",
"source": "A"
},
{
"id": 1,
"title": "Book B1",
"source": "B"
},
{
"id": 2,
"title": "Book A2",
"source": "A"
},
{
"id": 2,
"title": "Book B2",
"source": "B"
},
{
"id": 3,
"title": "Book A3",
"source": "A"
}
],
"page": {
"size": 5,
"number": 0,
"totalElements": 10,
"totalPages": 2
}
}
For further reference, please consider the following sections:
- Official Gradle documentation
- Spring Boot Gradle Plugin Reference Guide
- Create an OCI image
- Spring Boot Actuator
- Spring Web
The following guides illustrate how to use some features concretely:
- Building a RESTful Web Service with Spring Boot Actuator
- Building a RESTful Web Service
- Serving Web Content with Spring MVC
- Building REST services with Spring
These additional references should also help you: