Compare commits

..

No commits in common. "7cd3b063bcd3210859af58462a7e510124d9197d" and "ba13f2110254698f93e25b1722b9a597e16f3ca7" have entirely different histories.

11 changed files with 15 additions and 94 deletions

View File

@ -1,8 +0,0 @@
package com.techivw.webprice.application.exceptions;
public class NotFoundException extends RuntimeException {
public NotFoundException(String message) {
super(message);
}
}

View File

@ -1,6 +1,5 @@
package com.techivw.webprice.application.services; package com.techivw.webprice.application.services;
import com.techivw.webprice.application.exceptions.NotFoundException;
import com.techivw.webprice.application.ports.in.PriceServicePort; import com.techivw.webprice.application.ports.in.PriceServicePort;
import com.techivw.webprice.application.ports.out.PriceRepositoryPort; import com.techivw.webprice.application.ports.out.PriceRepositoryPort;
import com.techivw.webprice.domain.Price; import com.techivw.webprice.domain.Price;
@ -17,9 +16,6 @@ public class PriceService implements PriceServicePort {
@Override @Override
public Price getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId) { public Price getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId) {
return priceRepositoryPort.findHighestPriorityPriceByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId) return priceRepositoryPort.findHighestPriorityPriceByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId).orElse(null);
.orElseThrow(() ->
new NotFoundException(String.format(
"Price for product %d of brand %d not found for date %s", productId, brandId, dateTime)));
} }
} }

View File

@ -10,8 +10,3 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
# H2 console # H2 console
spring.h2.console.enabled=true spring.h2.console.enabled=true
spring.h2.console.path=/h2-console spring.h2.console.path=/h2-console
# Flyway
spring.flyway.enabled=true
spring.flyway.locations=filesystem:infrastructure/out/sql-repository/sql/migration
spring.flyway.baseline-on-migrate=true

View File

@ -3,7 +3,6 @@ package com.techivw.webprice.infrastructure.in.controllers.adapters;
import com.techivw.webprice.application.ports.in.PriceServicePort; import com.techivw.webprice.application.ports.in.PriceServicePort;
import com.techivw.webprice.domain.Price; import com.techivw.webprice.domain.Price;
import com.techivw.webprice.infrastructure.in.controllers.model.PriceResponse; import com.techivw.webprice.infrastructure.in.controllers.model.PriceResponse;
import com.techivw.webprice.infrastructure.in.controllers.model.mappers.PriceResponseMapper;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Content;
@ -36,8 +35,8 @@ public class PriceControllerAdapter {
description = "Price information found", description = "Price information found",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = PriceResponse.class)) content = @Content(mediaType = "application/json", schema = @Schema(implementation = PriceResponse.class))
) )
@ApiResponse(responseCode = "400", description = "Invalid request parameters")
@ApiResponse(responseCode = "404", description = "Price information not found for the given parameters") @ApiResponse(responseCode = "404", description = "Price information not found for the given parameters")
@ApiResponse(responseCode = "400", description = "Invalid request parameters")
public ResponseEntity<PriceResponse> getPrice( public ResponseEntity<PriceResponse> getPrice(
@Parameter(description = "Date and time for price lookup (ISO format)", example = "2025-04-30T12:00:00") @Parameter(description = "Date and time for price lookup (ISO format)", example = "2025-04-30T12:00:00")
@RequestParam(name = "dateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateTime, @RequestParam(name = "dateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateTime,
@ -47,6 +46,14 @@ public class PriceControllerAdapter {
@RequestParam(name = "brandId") Long brandId) { @RequestParam(name = "brandId") Long brandId) {
Price price = priceServicePort.getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId); Price price = priceServicePort.getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId);
return ResponseEntity.ok(PriceResponseMapper.fromPrice(price)); PriceResponse priceResponse = PriceResponse.builder()
.productId(price.getProductId())
.brandId(price.getBrandId())
.priceList(price.getPriceList())
.startDate(price.getStartDate())
.endDate(price.getEndDate())
.price(price.getPrice())
.build();
return ResponseEntity.ok(priceResponse);
} }
} }

View File

@ -1,27 +0,0 @@
package com.techivw.webprice.infrastructure.in.controllers.handlers;
import com.techivw.webprice.application.exceptions.NotFoundException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import static org.springframework.http.HttpStatus.NOT_FOUND;
@RestControllerAdvice
public class AdapterExceptionHandler {
@ExceptionHandler(NotFoundException.class)
public ResponseEntity<Map<String, Object>> handleNotFoundException(NotFoundException ex) {
Map<String, Object> body = new HashMap<>();
body.put("timestamp", new Date());
body.put("status", NOT_FOUND.value());
body.put("error", "Not Found");
body.put("message", ex.getMessage());
return new ResponseEntity<>(body, NOT_FOUND);
}
}

View File

@ -1,12 +1,10 @@
package com.techivw.webprice.infrastructure.in.controllers.model; package com.techivw.webprice.infrastructure.in.controllers.model;
import lombok.Builder; import lombok.Builder;
import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@Data
@Builder @Builder
public class PriceResponse { public class PriceResponse {

View File

@ -1,18 +0,0 @@
package com.techivw.webprice.infrastructure.in.controllers.model.mappers;
import com.techivw.webprice.domain.Price;
import com.techivw.webprice.infrastructure.in.controllers.model.PriceResponse;
public class PriceResponseMapper {
public static PriceResponse fromPrice(Price price) {
return PriceResponse.builder()
.productId(price.getProductId())
.brandId(price.getBrandId())
.priceList(price.getPriceList())
.startDate(price.getStartDate())
.endDate(price.getEndDate())
.price(price.getPrice())
.build();
}
}

View File

@ -26,15 +26,6 @@
<artifactId>application</artifactId> <artifactId>application</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>11.7.1</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,11 +0,0 @@
CREATE TABLE prices (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
brand_id BIGINT NOT NULL,
start_date TIMESTAMP NOT NULL,
end_date TIMESTAMP NOT NULL,
price_list BIGINT NOT NULL,
product_id BIGINT NOT NULL,
priority BIGINT NOT NULL,
price DECIMAL(10, 2) NOT NULL,
currency VARCHAR(3)
);

View File

@ -1,6 +0,0 @@
INSERT INTO prices (brand_id, start_date, end_date, price_list, product_id, priority, price, currency)
VALUES
(1, '2020-06-14 00:00:00', '2020-12-31 23:59:59', 1, 35455, 0, 35.50, 'EUR'),
(1, '2020-06-14 15:00:00', '2020-06-14 18:30:00', 2, 35455, 1, 25.45, 'EUR'),
(1, '2020-06-15 00:00:00', '2020-06-15 11:00:00', 3, 35455, 1, 30.50, 'EUR'),
(1, '2020-06-15 16:00:00', '2020-12-31 23:59:59', 4, 35455, 1, 38.95, 'EUR');

View File

@ -42,6 +42,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>