-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
189 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...module/src/main/java/com/likelion/apimodule/customer/application/CustomerFIndUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.likelion.apimodule.customer.application; | ||
|
||
import com.likelion.apimodule.customer.dto.TotalOrder; | ||
import com.likelion.apimodule.order.dto.MenuOrder; | ||
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; | ||
import com.likelion.coremodule.order.domain.OrderItem; | ||
import com.likelion.coremodule.order.service.OrderQueryService; | ||
import com.likelion.coremodule.user.application.UserQueryService; | ||
import com.likelion.coremodule.user.domain.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CustomerFIndUseCase { | ||
|
||
private final CustomerQueryService customerQueryService; | ||
private final MenuQueryService menuQueryService; | ||
private final OrderQueryService orderQueryService; | ||
private final UserQueryService userQueryService; | ||
|
||
public List<TotalOrder> getTotalOrder(Long storeId) { | ||
|
||
List<Menu> menus = menuQueryService.findMenusByStoreId(storeId); | ||
List<OrderItem> items = new ArrayList<>(); | ||
for (Menu menu : menus) { | ||
List<OrderItem> item = orderQueryService.findOrderItemsByMenuId(menu.getId()); | ||
items.addAll(item); | ||
} | ||
|
||
Map<Long, List<OrderItem>> groupedItems = new HashMap<>(); | ||
for (OrderItem item : items) { | ||
groupedItems.computeIfAbsent(item.getOrder().getId(), k -> new ArrayList<>()).add(item); | ||
} | ||
|
||
List<TotalOrder> totalOrders = new ArrayList<>(); | ||
|
||
for (Map.Entry<Long, List<OrderItem>> entry : groupedItems.entrySet()) { | ||
|
||
List<OrderItem> orderItems = entry.getValue(); | ||
Order order = orderQueryService.findOrderById(orderItems.get(0).getOrder().getId()); | ||
User user = userQueryService.findById(order.getUser().getUserId()); | ||
|
||
List<MenuOrder> 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(), | ||
order.getCreatedAt(), | ||
order.getOrderNum(), | ||
menuOrders, | ||
totalPrice | ||
); | ||
|
||
totalOrders.add(totalOrder); | ||
} | ||
|
||
return totalOrders; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...module/src/main/java/com/likelion/apimodule/customer/application/CustomerSaveUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.likelion.apimodule.customer.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CustomerSaveUseCase { | ||
} |
7 changes: 7 additions & 0 deletions
7
api-module/src/main/java/com/likelion/apimodule/customer/dto/OrderMenu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.likelion.apimodule.customer.dto; | ||
|
||
public record OrderMenu( | ||
Long menuId, | ||
String menuName | ||
) { | ||
} |
18 changes: 18 additions & 0 deletions
18
api-module/src/main/java/com/likelion/apimodule/customer/dto/TotalOrder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.likelion.apimodule.customer.dto; | ||
|
||
import com.likelion.apimodule.order.dto.MenuOrder; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public record TotalOrder( | ||
String pickUpRoute, | ||
String visitHour, | ||
String visitMin, | ||
String userName, | ||
LocalDateTime createdAt, | ||
String orderNum, | ||
List<MenuOrder> menu, | ||
Integer totalPrice | ||
) { | ||
} |
57 changes: 57 additions & 0 deletions
57
...module/src/main/java/com/likelion/apimodule/customer/presentation/CustomerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.likelion.apimodule.customer.presentation; | ||
|
||
import com.likelion.apimodule.customer.application.CustomerFIndUseCase; | ||
import com.likelion.apimodule.customer.application.CustomerSaveUseCase; | ||
import com.likelion.apimodule.customer.dto.TotalOrder; | ||
import com.likelion.commonmodule.exception.common.ApplicationResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/v1/customer") | ||
@Validated | ||
@Tag(name = "Customer", description = "Customer 관련 API") | ||
public class CustomerController { | ||
|
||
private final CustomerFIndUseCase customerFIndUseCase; | ||
private final CustomerSaveUseCase customerSaveUseCase; | ||
|
||
// 주문 전체 조회 (정후) | ||
@GetMapping("/{storeId}") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "주문 전체 조회", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "주문 전체 조회 API", description = "주문 전체 조회 API 입니다.") | ||
public ApplicationResponse<List<TotalOrder>> getTotalOrder( | ||
@PathVariable Long storeId | ||
) { | ||
|
||
List<TotalOrder> orders = customerFIndUseCase.getTotalOrder(storeId); | ||
return ApplicationResponse.ok(orders); | ||
} | ||
|
||
// 접수하는 API (정후) | ||
|
||
// 준비 완료 시키는 API (정후) | ||
|
||
// 메뉴 조회 API (소연) | ||
|
||
// 메뉴 추가 API (소연) | ||
} |
9 changes: 9 additions & 0 deletions
9
core-module/src/main/java/com/likelion/coremodule/customer/service/CustomerQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.likelion.coremodule.customer.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CustomerQueryService { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters