From 87b249789786afa46232094aafc5d0e471379971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Tue, 6 Aug 2024 02:41:12 +0900 Subject: [PATCH] fix: marketId & visitlist fix --- .../application/CustomerFIndUseCase.java | 80 ++++++++++--------- .../market/application/MarketInfoUseCase.java | 1 + .../apimodule/market/dto/VisitListInfo.java | 1 + .../repository/VisitListRepository.java | 2 + .../service/VisitListQueryService.java | 4 + 5 files changed, 51 insertions(+), 37 deletions(-) diff --git a/api-module/src/main/java/com/likelion/apimodule/customer/application/CustomerFIndUseCase.java b/api-module/src/main/java/com/likelion/apimodule/customer/application/CustomerFIndUseCase.java index 5f86b4c..62805f4 100644 --- a/api-module/src/main/java/com/likelion/apimodule/customer/application/CustomerFIndUseCase.java +++ b/api-module/src/main/java/com/likelion/apimodule/customer/application/CustomerFIndUseCase.java @@ -3,8 +3,9 @@ import com.likelion.apimodule.customer.dto.TotalOrder; import com.likelion.apimodule.order.dto.MenuOrder; import com.likelion.coremodule.VisitList.domain.VisitList; +import com.likelion.coremodule.VisitList.exception.VisitErrorCode; +import com.likelion.coremodule.VisitList.exception.VisitException; import com.likelion.coremodule.VisitList.service.VisitListQueryService; -import com.likelion.coremodule.customer.service.CustomerQueryService; import com.likelion.coremodule.menu.domain.Menu; import com.likelion.coremodule.menu.service.MenuQueryService; import com.likelion.coremodule.order.domain.Order; @@ -24,8 +25,7 @@ @Service @RequiredArgsConstructor public class CustomerFIndUseCase { - - private final CustomerQueryService customerQueryService; + private final MenuQueryService menuQueryService; private final OrderQueryService orderQueryService; private final UserQueryService userQueryService; @@ -52,40 +52,46 @@ public List getTotalOrder(Long storeId) { List orderItems = entry.getValue(); Order order = orderQueryService.findOrderById(orderItems.get(0).getOrder().getId()); User user = userQueryService.findById(order.getUser().getUserId()); - VisitList visitList = visitListQueryService.findVisitListByStoreIdAndUserId(storeId, user.getUserId()); - - List menuOrders = orderItems.stream() - .map(item -> { - - Menu menu = menuQueryService.findMenuById(item.getMenu().getId()); - - return new MenuOrder( - menu.getName(), - menu.getImageUrl(), - item.getQuantity(), - menu.getPrice() * item.getQuantity() - ); - }) - .collect(Collectors.toList()); - - Integer totalPrice = menuOrders.stream() - .mapToInt(MenuOrder::totalPrice) - .sum(); - - TotalOrder totalOrder = new TotalOrder( - order.getPickUpRoute(), - order.getVisitHour().toString(), - order.getVisitMin().toString(), - user.getName(), - visitList.getVisit_status(), - order.getCreatedAt(), - order.getId(), - order.getOrderNum(), - menuOrders, - totalPrice - ); - - totalOrders.add(totalOrder); + + VisitList visitList; + if (visitListQueryService.countVisitListByStoreAndUser(storeId, user.getUserId()) > 0) { + visitList = visitListQueryService.findVisitListByStoreIdAndUserId(storeId, user.getUserId()); + + List menuOrders = orderItems.stream() + .map(item -> { + + Menu menu = menuQueryService.findMenuById(item.getMenu().getId()); + + return new MenuOrder( + menu.getName(), + menu.getImageUrl(), + item.getQuantity(), + menu.getPrice() * item.getQuantity() + ); + }) + .collect(Collectors.toList()); + + Integer totalPrice = menuOrders.stream() + .mapToInt(MenuOrder::totalPrice) + .sum(); + + TotalOrder totalOrder = new TotalOrder( + order.getPickUpRoute(), + order.getVisitHour().toString(), + order.getVisitMin().toString(), + user.getName(), + visitList.getVisit_status(), + order.getCreatedAt(), + order.getId(), + order.getOrderNum(), + menuOrders, + totalPrice + ); + + totalOrders.add(totalOrder); + } else { + throw new VisitException(VisitErrorCode.NO_VISIT_LIST_INFO); + } } return totalOrders; diff --git a/api-module/src/main/java/com/likelion/apimodule/market/application/MarketInfoUseCase.java b/api-module/src/main/java/com/likelion/apimodule/market/application/MarketInfoUseCase.java index b1d5d8e..c3f0fa8 100644 --- a/api-module/src/main/java/com/likelion/apimodule/market/application/MarketInfoUseCase.java +++ b/api-module/src/main/java/com/likelion/apimodule/market/application/MarketInfoUseCase.java @@ -151,6 +151,7 @@ public Map> findTodayVisitList(String accessToken return new VisitListInfo( id, + store.getMarket().getId(), store.getId(), store.getName(), store.getCategory(), diff --git a/api-module/src/main/java/com/likelion/apimodule/market/dto/VisitListInfo.java b/api-module/src/main/java/com/likelion/apimodule/market/dto/VisitListInfo.java index 3bd4c22..5f941e2 100644 --- a/api-module/src/main/java/com/likelion/apimodule/market/dto/VisitListInfo.java +++ b/api-module/src/main/java/com/likelion/apimodule/market/dto/VisitListInfo.java @@ -4,6 +4,7 @@ import com.likelion.coremodule.store.domain.StoreCategory; public record VisitListInfo(Long visitListId, + Long marketId, Long storeId, String store, StoreCategory category, diff --git a/core-module/src/main/java/com/likelion/coremodule/VisitList/repository/VisitListRepository.java b/core-module/src/main/java/com/likelion/coremodule/VisitList/repository/VisitListRepository.java index 48d1c2d..cbbd9e8 100644 --- a/core-module/src/main/java/com/likelion/coremodule/VisitList/repository/VisitListRepository.java +++ b/core-module/src/main/java/com/likelion/coremodule/VisitList/repository/VisitListRepository.java @@ -13,4 +13,6 @@ public interface VisitListRepository extends JpaRepository { List findVisitListsByUserUserId(Long userId); VisitList findVisitListByStoreIdAndUserUserId(Long storeId, Long userId); + + Integer countVisitListsByStoreIdAndUserUserId(Long storeId, Long userId); } diff --git a/core-module/src/main/java/com/likelion/coremodule/VisitList/service/VisitListQueryService.java b/core-module/src/main/java/com/likelion/coremodule/VisitList/service/VisitListQueryService.java index 532b4c9..a751f84 100644 --- a/core-module/src/main/java/com/likelion/coremodule/VisitList/service/VisitListQueryService.java +++ b/core-module/src/main/java/com/likelion/coremodule/VisitList/service/VisitListQueryService.java @@ -31,6 +31,10 @@ public List findVisitListsByUserId(Long userId) { return visitListRepository.findVisitListsByUserUserId(userId); } + public Integer countVisitListByStoreAndUser(Long storeId, Long userId) { + return visitListRepository.countVisitListsByStoreIdAndUserUserId(storeId, userId); + } + public VisitList findVisitListByStoreIdAndUserId(Long storeId, Long userId) { return visitListRepository.findVisitListByStoreIdAndUserUserId(storeId, userId); }