Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Prices Service

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.

Stack

  • Java 17
  • Spring Boot 3.3.x (Web, Data JPA, Validation)
  • H2 (in-memory)
  • JUnit 5, Spring MockMvc, Mockito

Architecture — hexagonal (ports & adapters)

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.

Running

./mvnw spring-boot:run
# or
mvn spring-boot:run

Service listens on http://localhost:8080. H2 console at http://localhost:8080/h2-console (JDBC URL jdbc:h2:mem:prices).

Endpoints

GET /api/v1/prices

Query param Type Example
brandId long 1
productId long 35455
applicationDate ISO-8601 datetime 2020-06-14T16:00:00

Request Example

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.

Tests

mvn test
  • PriceServiceTest — 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages