Skip to content

Commit

Permalink
feat: 가게마다 메뉴별 주문 확인 api 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
summit45 committed Nov 19, 2023
1 parent 1fcbedf commit a528852
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/com/kusitms/jipbap/order/OrderController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.kusitms.jipbap.order;

import com.kusitms.jipbap.common.response.CommonResponse;
import com.kusitms.jipbap.order.dto.OrderDto;
import com.kusitms.jipbap.order.dto.OrderFoodRequest;
import com.kusitms.jipbap.order.dto.OrderFoodResponse;
import com.kusitms.jipbap.order.dto.OrderHistoryResponse;
import com.kusitms.jipbap.order.dto.*;
import com.kusitms.jipbap.security.Auth;
import com.kusitms.jipbap.security.AuthInfo;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -55,4 +52,11 @@ public CommonResponse<String> processOrder(
public CommonResponse<List<OrderHistoryResponse>> getMyOrderHistory(@Auth AuthInfo authInfo) {
return new CommonResponse<>(orderService.getMyOrderHistory(authInfo.getEmail()));
}

@Operation(summary = "주문내역 중 진행 중인 메뉴 조회하기")
@GetMapping("/processing")
@ResponseStatus(HttpStatus.OK)
public CommonResponse<StoreProcessingResponse> getStoreProcessingOrder(@Auth AuthInfo authInfo) {
return new CommonResponse<>(orderService.getStoreProcessingOrder(authInfo.getEmail()));
}
}
45 changes: 45 additions & 0 deletions src/main/java/com/kusitms/jipbap/order/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,49 @@ public List<OrderHistoryResponse> getMyOrderHistory(String email) {
return orderFoodResponseList;
}

public StoreProcessingResponse getStoreProcessingOrder(String email){
User user = userRepository.findByEmail(email)
.orElseThrow(() -> new UserNotFoundException("해당 유저를 찾을 수 없습니다."));

Store store = storeRepository.findByOwner(user)
.orElseThrow(() -> new StoreNotExistsException("해당 유저의 가게를 찾을 수 없습니다."));

//전체 주문내역에서 해당 가게에 속하는 주문내역만 가져오기
List<Order> orderList = orderRepository.findByStore_IdAndStatus(store.getId(), OrderStatus.ACCEPTED)
.orElseThrow(() -> new OrderNotExistsByOrderStatusException("해당 가게의 주문상태에 따른 주문 내역이 존재하지 않습니다."));

if (orderList.isEmpty()) {
throw new OrderNotExistsByOrderStatusException("해당 가게의 주문상태에 따른 주문 내역이 존재하지 않습니다.");
}

//주문내역 중에서 음식별로 묶기
List<OrderDetail> orderDetailList = orderList.stream()
.flatMap(order -> order.getOrderDetail().stream())
.collect(Collectors.toList());

//음식 옵션별로 묶어서 음식별로 묶기
List<ProcessingFoodResponse> processingFoodResponseList = orderDetailList.stream()
.collect(Collectors.groupingBy(OrderDetail::getFood))
.entrySet().stream()
.map(entry -> {
Food food = entry.getKey();
List<ProcessingFoodDetailResponse> processingFoodDetailResponseList = entry.getValue().stream()
.collect(Collectors.groupingBy(OrderDetail::getFoodOption,
Collectors.summingLong(OrderDetail::getOrderCount)))
.entrySet().stream()
.map(entry2 -> new ProcessingFoodDetailResponse(
entry2.getKey().getId(),
entry2.getKey().getName(),
entry2.getValue()))
.collect(Collectors.toList());
long totalOrderCount = processingFoodDetailResponseList.stream()
.mapToLong(ProcessingFoodDetailResponse::getOrderCount)
.sum();
return new ProcessingFoodResponse(food.getId(), food.getName(), totalOrderCount, processingFoodDetailResponseList);
})
.collect(Collectors.toList());

return new StoreProcessingResponse(orderList.size(), processingFoodResponseList);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.kusitms.jipbap.order.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class ProcessingFoodDetailResponse {
private Long foodOptionId;
private String foodOptionName;
private Long orderCount;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.kusitms.jipbap.order.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class ProcessingFoodResponse {
private Long foodId;
private String foodName;
private Long totalOrderCount;
private List<ProcessingFoodDetailResponse> processingFoodDetailList;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.kusitms.jipbap.order.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class StoreProcessingResponse {
int orderCount;
List<ProcessingFoodResponse> processingFoodList;
}

0 comments on commit a528852

Please sign in to comment.