diff --git a/src/main/java/com/jangburich/domain/store/controller/StoreController.java b/src/main/java/com/jangburich/domain/store/controller/StoreController.java index 23572db..7bbd9c2 100644 --- a/src/main/java/com/jangburich/domain/store/controller/StoreController.java +++ b/src/main/java/com/jangburich/domain/store/controller/StoreController.java @@ -26,6 +26,7 @@ import com.jangburich.domain.store.domain.StoreUpdateRequestDTO; import com.jangburich.domain.store.dto.condition.StoreSearchCondition; import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType; +import com.jangburich.domain.store.dto.response.OrdersDetailResponse; import com.jangburich.domain.store.dto.response.OrdersGetResponse; import com.jangburich.domain.store.dto.response.PaymentGroupDetailResponse; import com.jangburich.domain.store.dto.response.SearchStoresResponse; @@ -122,4 +123,12 @@ public ResponseCustom> getOrders(Authentication authenti AuthenticationParser.parseUserId(authentication)); return ResponseCustom.OK(ordersLast); } + + @Operation(summary = "주문 상세 조회", description = "가게에 있는 주문을 상세 조회합니다") + @GetMapping("/orders/{ordersId}") + public ResponseCustom getOrders(Authentication authentication, @RequestParam Long orderId) { + return ResponseCustom.OK( + storeService.getOrderDetails(AuthenticationParser.parseUserId(authentication), orderId)); + } + } \ No newline at end of file diff --git a/src/main/java/com/jangburich/domain/store/dto/response/OrdersDetailResponse.java b/src/main/java/com/jangburich/domain/store/dto/response/OrdersDetailResponse.java new file mode 100644 index 0000000..73b5c28 --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/dto/response/OrdersDetailResponse.java @@ -0,0 +1,30 @@ +package com.jangburich.domain.store.dto.response; + +import java.time.LocalDateTime; +import java.util.List; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +public class OrdersDetailResponse { + private Long id; + private String teamName; + private String teamUserName; + private List menus; + private LocalDateTime dateTime; + private Integer amount; + private Integer totalPrice; + private Integer discountPrice; + + @Getter + @Setter + public static class Menu { + private String menuName; + private Integer amount; + } +} + diff --git a/src/main/java/com/jangburich/domain/store/exception/OrdersNotFoundException.java b/src/main/java/com/jangburich/domain/store/exception/OrdersNotFoundException.java new file mode 100644 index 0000000..6328c5d --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/exception/OrdersNotFoundException.java @@ -0,0 +1,7 @@ +package com.jangburich.domain.store.exception; + +public class OrdersNotFoundException extends RuntimeException { + public OrdersNotFoundException() { + super("해당 가게를 찾을 수 없습니다."); + } +} diff --git a/src/main/java/com/jangburich/domain/store/service/StoreService.java b/src/main/java/com/jangburich/domain/store/service/StoreService.java index b688145..7dc9ec3 100644 --- a/src/main/java/com/jangburich/domain/store/service/StoreService.java +++ b/src/main/java/com/jangburich/domain/store/service/StoreService.java @@ -33,9 +33,11 @@ import com.jangburich.domain.store.domain.StoreUpdateRequestDTO; import com.jangburich.domain.store.dto.condition.StoreSearchCondition; import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType; +import com.jangburich.domain.store.dto.response.OrdersDetailResponse; import com.jangburich.domain.store.dto.response.OrdersGetResponse; import com.jangburich.domain.store.dto.response.PaymentGroupDetailResponse; import com.jangburich.domain.store.dto.response.SearchStoresResponse; +import com.jangburich.domain.store.exception.OrdersNotFoundException; import com.jangburich.domain.store.repository.StoreRepository; import com.jangburich.domain.store.repository.StoreTeamRepository; import com.jangburich.domain.team.domain.Team; @@ -271,12 +273,13 @@ public List getOrdersLast(String userId) { OrdersGetResponse newOrdersGetResponse = new OrdersGetResponse(); List carts = cartRepository.findAllByOrders(orders); newOrdersGetResponse.setId(orders.getId()); - newOrdersGetResponse.setMenuNames(carts.size() == 1 ? carts.get(0).getMenu().getName() :carts.get(0).getMenu().getName() + "외 " + (carts.size() - 1) + "개"); + newOrdersGetResponse.setMenuNames(carts.size() == 1 ? carts.get(0).getMenu().getName() : + carts.get(0).getMenu().getName() + "외 " + (carts.size() - 1) + "개"); newOrdersGetResponse.setCount(carts.size()); newOrdersGetResponse.setDate(orders.getUpdatedAt()); Integer price = 0; for (Cart cart : carts) { - price += cart.getMenu().getPrice(); + price += (cart.getMenu().getPrice() * cart.getQuantity()); } newOrdersGetResponse.setPrice(price); ordersGetResponses.add(newOrdersGetResponse); @@ -284,4 +287,37 @@ public List getOrdersLast(String userId) { return ordersGetResponses; } + + public OrdersDetailResponse getOrderDetails(String userId, Long orderId) { + OrdersDetailResponse ordersDetailResponse = new OrdersDetailResponse(); + + userRepository.findByProviderId(userId) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Orders orders = ordersRepository.findById(orderId).orElseThrow(OrdersNotFoundException::new); + + ordersDetailResponse.setId(orders.getId()); + ordersDetailResponse.setTeamName(orders.getTeam().getName()); + ordersDetailResponse.setTeamUserName(orders.getUser().getName()); + + List carts = cartRepository.findAllByOrders(orders); + List menus = new ArrayList<>(); + Integer amount = 0; + Integer price = 0; + for (Cart cart : carts) { + OrdersDetailResponse.Menu menu = new OrdersDetailResponse.Menu(); + menu.setMenuName(cart.getMenu().getName()); + menu.setAmount(cart.getQuantity()); + menus.add(menu); + amount += cart.getQuantity(); + price += (cart.getQuantity() * cart.getMenu().getPrice()); + } + ordersDetailResponse.setMenus(menus); + ordersDetailResponse.setDateTime(orders.getUpdatedAt()); + ordersDetailResponse.setAmount(amount); + ordersDetailResponse.setTotalPrice(price); + ordersDetailResponse.setDiscountPrice(0); + + return ordersDetailResponse; + } }