This is a REST API built using Spring Boot that allows users to register batteries and query them based on postcode range and capacity. The API uses PostgreSQL for data persistence, Flyway for database migrations, and integrates OpenAPI for documentation.
- Add multiple batteries in a single request.
- Query batteries within a postcode range.
- Filter results by minimum and maximum watt capacity.
- Retrieve sorted battery names along with total and average capacity.
- Integrated logging for system events.
- Java 21
- Spring Boot 3
- Spring Data JPA
- PostgreSQL
- Flyway
- Lombok
- Mockito & JUnit 5 for testing
- OpenAPI (Swagger)
- Java 21
- PostgreSQL database
- Clone the repository:
git clone https://github.com/your-repo/battery-api.git cd battery-api
- Configure PostgreSQL connection in
application.properties
:spring.datasource.url=jdbc:postgresql://localhost:5432/vpp spring.datasource.username=your_username spring.datasource.password=your_password
- Run Flyway migrations:
mvn flyway:migrate
- Build and run the application:
mvn spring-boot:run
POST /batteries
- Request Body:
[ { "name": "Cannington", "postcode": "6107", "capacity": 13500 } ]
- Response:
[ { "id": 1, "name": "Cannington", "postcode": "6107", "capacity": 13500 } ]
GET /batteries?startPostcode=6000&endPostcode=6100&minCapacity=10000&maxCapacity=50000
- Response:
{ "names": ["Battery A", "Battery B"], "totalCapacity": 45000, "avgCapacity": 22500.0 }
To run unit tests:
mvn test
- The application logs significant events such as battery additions and queries.
Once the application is running, visit:
- Swagger UI:
http://localhost:8080/swagger-ui.html
- API Docs:
http://localhost:8080/v3/api-docs