Compare commits

..

2 Commits

18 changed files with 353 additions and 105 deletions

View File

@ -1,19 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip

View File

@ -10,14 +10,16 @@
<parent> <parent>
<groupId>com.techivw</groupId> <groupId>com.techivw</groupId>
<artifactId>webprice</artifactId> <artifactId>web-price</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath/>
</parent> </parent>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.techivw</groupId> <groupId>com.techivw</groupId>
<artifactId>domain</artifactId> <artifactId>domain</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -0,0 +1,11 @@
package com.techivw.webprice.application.ports.in;
import com.techivw.webprice.domain.Price;
import java.time.LocalDateTime;
public interface PriceServicePort {
Price getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId);
}

View File

@ -0,0 +1,12 @@
package com.techivw.webprice.application.ports.out;
import com.techivw.webprice.domain.Price;
import java.time.LocalDateTime;
import java.util.Optional;
public interface PriceRepositoryPort {
Optional<Price> findHighestPriorityPriceByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId);
}

View File

@ -0,0 +1,21 @@
package com.techivw.webprice.application.services;
import com.techivw.webprice.application.ports.in.PriceServicePort;
import com.techivw.webprice.application.ports.out.PriceRepositoryPort;
import com.techivw.webprice.domain.Price;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
@Service
@AllArgsConstructor
public class PriceService implements PriceServicePort {
PriceRepositoryPort priceRepositoryPort;
@Override
public Price getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId) {
return priceRepositoryPort.findHighestPriorityPriceByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId).orElse(null);
}
}

View File

@ -4,67 +4,47 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.techivw</groupId>
<artifactId>web-price</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath/>
</parent>
<artifactId>boot</artifactId> <artifactId>boot</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>boot</name> <name>boot</name>
<parent>
<groupId>com.techivw</groupId>
<artifactId>webprice</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies> <dependencies>
<!-- Project modules -->
<dependency> <dependency>
<groupId>com.techivw</groupId> <groupId>com.techivw</groupId>
<artifactId>domain</artifactId> <artifactId>domain</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.techivw</groupId> <groupId>com.techivw</groupId>
<artifactId>application</artifactId> <artifactId>application</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.techivw</groupId> <groupId>com.techivw</groupId>
<artifactId>rest-api</artifactId> <artifactId>rest-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.techivw</groupId> <groupId>com.techivw</groupId>
<artifactId>sql-repository</artifactId> <artifactId>sql-repository</artifactId>
</dependency> <version>0.0.1-SNAPSHOT</version>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project>
</project>

View File

@ -1 +1,12 @@
spring.application.name=webprice spring.application.name=webprice
# Database Configuration
spring.datasource.url=jdbc:h2:mem:webprice
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=admin
spring.datasource.password=admin
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
# H2 console
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

View File

@ -10,8 +10,7 @@
<parent> <parent>
<groupId>com.techivw</groupId> <groupId>com.techivw</groupId>
<artifactId>webprice</artifactId> <artifactId>web-price</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
</project> </project>

View File

@ -0,0 +1,23 @@
package com.techivw.webprice.domain;
import lombok.Builder;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@Builder
public class Price {
private Long id;
private Long brandId;
private LocalDateTime startDate;
private LocalDateTime endDate;
private Long priceList;
private Long productId;
private Integer priority;
private BigDecimal price;
private String currency;
}

View File

@ -4,24 +4,27 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.techivw</groupId>
<artifactId>web-price</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<artifactId>rest-api</artifactId> <artifactId>rest-api</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>rest-api</name> <name>rest-api</name>
<parent>
<groupId>com.techivw</groupId>
<artifactId>webprice</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.techivw</groupId> <groupId>com.techivw</groupId>
<artifactId>domain</artifactId> <artifactId>domain</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.techivw</groupId> <groupId>com.techivw</groupId>
<artifactId>application</artifactId> <artifactId>application</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -0,0 +1,59 @@
package com.techivw.webprice.infrastructure.in.controllers.adapters;
import com.techivw.webprice.application.ports.in.PriceServicePort;
import com.techivw.webprice.domain.Price;
import com.techivw.webprice.infrastructure.in.controllers.model.PriceResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.AllArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
@RestController
@AllArgsConstructor
@RequestMapping("/price")
public class PriceControllerAdapter {
private PriceServicePort priceServicePort;
@GetMapping
@Operation(
summary = "Get product price",
description = "Returns the current price for a specific product from a particular brand at a given date and time"
)
@ApiResponse(
responseCode = "200",
description = "Price information found",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = PriceResponse.class))
)
@ApiResponse(responseCode = "404", description = "Price information not found for the given parameters")
@ApiResponse(responseCode = "400", description = "Invalid request parameters")
public ResponseEntity<PriceResponse> getPrice(
@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,
@Parameter(description = "Product ID", example = "35455")
@RequestParam(name = "productId") Long productId,
@Parameter(description = "Brand ID", example = "1")
@RequestParam(name = "brandId") Long brandId) {
Price price = priceServicePort.getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId);
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

@ -0,0 +1,17 @@
package com.techivw.webprice.infrastructure.in.controllers.model;
import lombok.Builder;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Builder
public class PriceResponse {
private Long productId;
private Long brandId;
private Long priceList;
private LocalDateTime startDate;
private LocalDateTime endDate;
private BigDecimal price;
}

View File

@ -10,18 +10,21 @@
<parent> <parent>
<groupId>com.techivw</groupId> <groupId>com.techivw</groupId>
<artifactId>webprice</artifactId> <artifactId>web-price</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent> </parent>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.techivw</groupId> <groupId>com.techivw</groupId>
<artifactId>domain</artifactId> <artifactId>domain</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.techivw</groupId> <groupId>com.techivw</groupId>
<artifactId>application</artifactId> <artifactId>application</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -0,0 +1,20 @@
package com.techivw.webprice.infrastructure.repositories;
import com.techivw.webprice.infrastructure.repositories.model.PriceEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.Optional;
@Repository
public interface PriceEntityJPARepository extends JpaRepository<PriceEntity, Long> {
@Query("SELECT p FROM PriceEntity p WHERE " +
"p.productId = :productId " +
"AND p.brandId = :brandId " +
"AND :dateTime BETWEEN p.startDate AND p.endDate " +
"ORDER BY p.priority DESC LIMIT 1")
Optional<PriceEntity> findPriceByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId);
}

View File

@ -0,0 +1,28 @@
package com.techivw.webprice.infrastructure.repositories.adapters;
import com.techivw.webprice.application.ports.out.PriceRepositoryPort;
import com.techivw.webprice.domain.Price;
import com.techivw.webprice.infrastructure.repositories.PriceEntityJPARepository;
import com.techivw.webprice.infrastructure.repositories.mappers.PriceEntityMapper;
import com.techivw.webprice.infrastructure.repositories.model.PriceEntity;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Optional;
@Service
@AllArgsConstructor
public class PriceRepositoryAdapter implements PriceRepositoryPort {
private final PriceEntityJPARepository repository;
@Override
public Optional<Price> findHighestPriorityPriceByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId) {
Optional<PriceEntity> priceEntity =
repository.findPriceByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId);
return PriceEntityMapper.toOptionalPrice(priceEntity);
}
}

View File

@ -0,0 +1,28 @@
package com.techivw.webprice.infrastructure.repositories.mappers;
import com.techivw.webprice.domain.Price;
import com.techivw.webprice.infrastructure.repositories.model.PriceEntity;
import java.util.Optional;
public class PriceEntityMapper {
public static Price toPrice(PriceEntity priceEntity) {
return Price.builder()
.id(priceEntity.getId())
.brandId(priceEntity.getBrandId())
.startDate(priceEntity.getStartDate())
.endDate(priceEntity.getEndDate())
.priceList(priceEntity.getPriceList())
.productId(priceEntity.getProductId())
.priority(priceEntity.getPriority())
.price(priceEntity.getPrice())
.currency(priceEntity.getCurrency())
.build();
}
public static Optional<Price> toOptionalPrice(Optional<PriceEntity> priceEntity) {
return priceEntity.map(PriceEntityMapper::toPrice);
}
}

View File

@ -0,0 +1,47 @@
package com.techivw.webprice.infrastructure.repositories.model;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Entity
@Getter
@Setter
@Table(name = "prices")
public class PriceEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "brand_id")
private Long brandId;
@Column(name = "start_date")
@Temporal(TemporalType.TIMESTAMP)
private LocalDateTime startDate;
@Column(name = "end_date")
@Temporal(TemporalType.TIMESTAMP)
private LocalDateTime endDate;
@Column(name = "price_list")
private Long priceList;
@Column(name = "product_id")
private Long productId;
@Column(name = "priority")
private Integer priority;
@Column(name = "price")
private BigDecimal price;
@Column(name = "currency")
private String currency;
}

89
pom.xml
View File

@ -3,49 +3,6 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.techivw</groupId>
<artifactId>webprice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>web-price</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.techivw</groupId>
<artifactId>domain</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.techivw</groupId>
<artifactId>application</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.techivw</groupId>
<artifactId>rest-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.techivw</groupId>
<artifactId>sql-repository</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.techivw</groupId>
<artifactId>boot</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules> <modules>
<module>domain</module> <module>domain</module>
<module>application</module> <module>application</module>
@ -53,4 +10,50 @@
<module>infrastructure/out/sql-repository</module> <module>infrastructure/out/sql-repository</module>
<module>boot</module> <module>boot</module>
</modules> </modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.4</version>
<relativePath/>
</parent>
<groupId>com.techivw</groupId>
<artifactId>web-price</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>web-price</name>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<!-- Project dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.6</version>
</dependency>
</dependencies>
</project> </project>