Spring Boot service that exposes a REST endpoint to query the applicable price (PVP and price list) for a given product, brand and instant in time, based on a PRICES table backed by an in-memory H2 database.
- Java 17
- Spring Boot 3.3.x (Web, Data JPA, Validation)
- H2 (in-memory)
- JUnit 5, Spring MockMvc, Mockito
com.bcnc.inditex.prices
├── domain
│ ├── model Price (record)
│ ├── port.in FindApplicablePriceUseCase
│ ├── port.out PriceRepository
│ ├── service PriceService (use case implementation)
│ └── exception PriceNotFoundException
└── infrastructure.adapter
├── in.rest PriceController, RestExceptionHandler, dto.PriceResponse
└── out.persistence PriceJpaEntity, PriceJpaRepository, PriceRepositoryAdapter
Considerations:
- The domain layer has no Spring or JPA imports beyond
@Service. - The REST and persistence adapters depend on the domain, never the other way around.
./mvnw spring-boot:run
# or
mvn spring-boot:runService listens on http://localhost:8080. H2 console at
http://localhost:8080/h2-console (JDBC URL jdbc:h2:mem:prices).
| Query param | Type | Example |
|---|---|---|
brandId |
long | 1 |
productId |
long | 35455 |
applicationDate |
ISO-8601 datetime | 2020-06-14T16:00:00 |
curl "http://localhost:8080/api/v1/prices?brandId=1&productId=35455&applicationDate=2020-06-14T16:00:00"{
"productId": 35455,
"brandId": 1,
"priceList": 2,
"startDate": "2020-06-14T15:00:00",
"endDate": "2020-06-14T18:30:00",
"price": 25.45,
"currency": "EUR"
}Returns 404 when no price applies, 400 when a parameter is missing or malformed.
mvn testPriceServiceTest— unit tests for the use case implementation mocking repository.PriceControllerIT— full Spring context + MockMvc, covering the five requiredscenarios plus 404 / 400 paths.
| # | Date / time | Expected price list | Expected price |
|---|---|---|---|
| 1 | 2020-06-14 10:00:00 | 1 | 35.50 |
| 2 | 2020-06-14 16:00:00 | 2 | 25.45 |
| 3 | 2020-06-14 21:00:00 | 1 | 35.50 |
| 4 | 2020-06-15 10:00:00 | 3 | 30.50 |
| 5 | 2020-06-16 21:00:00 | 4 | 38.95 |