Merge branch 'main' of https://github.com/dg04-hi/hi-backend
This commit is contained in:
@@ -14,6 +14,7 @@ public class Order {
|
||||
private Long id;
|
||||
private Long storeId;
|
||||
private Long menuId;
|
||||
private String menuName;
|
||||
private Integer customerAge;
|
||||
private String customerGender;
|
||||
private BigDecimal orderAmount;
|
||||
|
||||
@@ -28,12 +28,27 @@ public class OrderRepositoryAdapter implements OrderRepositoryPort {
|
||||
|
||||
@Override
|
||||
public List<Order> findOrdersByStoreIdAndPeriod(Long storeId, LocalDateTime startDate, LocalDateTime endDate) {
|
||||
return orderJpaRepository.findByStoreIdAndOrderDateBetween(storeId, startDate, endDate)
|
||||
.stream()
|
||||
.map(this::toDomain)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// return orderJpaRepository.findByStoreIdAndOrderDateBetween(storeId, startDate, endDate)
|
||||
// .stream()
|
||||
// .map(this::toDomain)
|
||||
// .collect(Collectors.toList());
|
||||
|
||||
return orderJpaRepository.findByStoreIdAndOrderDateBetweenWithMenuName(storeId, startDate, endDate)
|
||||
.stream()
|
||||
.map(result -> {
|
||||
OrderEntity entity = (OrderEntity) result[0];
|
||||
String menuName = (String) result[1];
|
||||
|
||||
Order order = this.toDomain(entity); // 기존 toDomain 메서드 활용
|
||||
order.setMenuName(menuName); // menuName만 별도로 설정
|
||||
return order;
|
||||
})
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<Order> findOrderById(Long orderId) {
|
||||
return orderJpaRepository.findById(orderId)
|
||||
|
||||
+14
@@ -1,12 +1,16 @@
|
||||
package com.ktds.hi.store.infra.gateway.repository;
|
||||
|
||||
import com.ktds.hi.store.domain.Order;
|
||||
import com.ktds.hi.store.infra.gateway.entity.OrderEntity;
|
||||
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.List;
|
||||
|
||||
import io.lettuce.core.dynamic.annotation.Param;
|
||||
|
||||
@Repository
|
||||
public interface OrderJpaRepository extends JpaRepository<OrderEntity, Long> {
|
||||
|
||||
@@ -17,4 +21,14 @@ public interface OrderJpaRepository extends JpaRepository<OrderEntity, Long> {
|
||||
LocalDateTime startDate,
|
||||
LocalDateTime endDate
|
||||
);
|
||||
|
||||
//기간 조회시, 메뉴명을 조회하기 위해서 조인하는 쿼리
|
||||
@Query("SELECT o, m.menuName FROM OrderEntity o LEFT JOIN MenuEntity m ON o.menuId = m.id " +
|
||||
"WHERE o.storeId = :storeId AND o.orderDate BETWEEN :startDate AND :endDate")
|
||||
List<Object[]> findByStoreIdAndOrderDateBetweenWithMenuName(
|
||||
@Param("storeId") Long storeId,
|
||||
@Param("startDate") LocalDateTime startDate,
|
||||
@Param("endDate") LocalDateTime endDate
|
||||
);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user