-
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.
Merge pull request #24 from LikeLion-Hackathon-T1/feat/customer
Feat/customer
- Loading branch information
Showing
21 changed files
with
371 additions
and
26 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
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
92 changes: 92 additions & 0 deletions
92
...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,92 @@ | ||
package com.likelion.apimodule.customer.application; | ||
|
||
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.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; | ||
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; | ||
private final VisitListQueryService visitListQueryService; | ||
|
||
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()); | ||
VisitList visitList = visitListQueryService.findVisitListByStoreIdAndUserId(storeId, user.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(), | ||
visitList.getVisit_status(), | ||
order.getCreatedAt(), | ||
order.getOrderNum(), | ||
menuOrders, | ||
totalPrice | ||
); | ||
|
||
totalOrders.add(totalOrder); | ||
} | ||
|
||
return totalOrders; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...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,59 @@ | ||
package com.likelion.apimodule.customer.application; | ||
|
||
import com.likelion.apimodule.customer.dto.AddMenu; | ||
import com.likelion.commonmodule.image.service.AwsS3Service; | ||
import com.likelion.coremodule.VisitList.domain.VisitList; | ||
import com.likelion.coremodule.VisitList.service.VisitListQueryService; | ||
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.service.OrderQueryService; | ||
import com.likelion.coremodule.store.domain.Store; | ||
import com.likelion.coremodule.store.service.StoreQueryService; | ||
import com.likelion.coremodule.user.application.UserQueryService; | ||
import com.likelion.coremodule.user.domain.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class CustomerSaveUseCase { | ||
|
||
private final VisitListQueryService visitListQueryService; | ||
private final OrderQueryService orderQueryService; | ||
private final UserQueryService userQueryService; | ||
private final StoreQueryService storeQueryService; | ||
private final AwsS3Service awsS3Service; | ||
private final MenuQueryService menuQueryService; | ||
|
||
public void changeToPreparing(Long storeId, Long orderId) { | ||
|
||
Order order = orderQueryService.findOrderById(orderId); | ||
User user = userQueryService.findById(order.getUser().getUserId()); | ||
|
||
VisitList visitList = visitListQueryService.findVisitListByStoreIdAndUserId(storeId, user.getUserId()); | ||
visitList.updateToPreparing(); | ||
} | ||
|
||
public void changeToPrepared(Long storeId, Long orderId) { | ||
|
||
Order order = orderQueryService.findOrderById(orderId); | ||
User user = userQueryService.findById(order.getUser().getUserId()); | ||
|
||
VisitList visitList = visitListQueryService.findVisitListByStoreIdAndUserId(storeId, user.getUserId()); | ||
visitList.updateToPrepared(); | ||
} | ||
|
||
public void addMenuInfo(Long storeId, AddMenu addMenu, MultipartFile multipartFile) { | ||
|
||
Store store = storeQueryService.findStoreById(storeId); | ||
String imageUrl = awsS3Service.uploadFile(multipartFile); | ||
|
||
final Menu menu = Menu.builder().store(store).name(addMenu.name()).content(addMenu.content()). | ||
imageUrl(imageUrl).price(addMenu.price()).build(); | ||
menuQueryService.saveMenu(menu); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
api-module/src/main/java/com/likelion/apimodule/customer/dto/AddMenu.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,8 @@ | ||
package com.likelion.apimodule.customer.dto; | ||
|
||
public record AddMenu( | ||
String name, | ||
Integer price, | ||
String content | ||
) { | ||
} |
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 | ||
) { | ||
} |
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
package com.likelion.apimodule.customer.dto; | ||
|
||
import com.likelion.apimodule.order.dto.MenuOrder; | ||
import com.likelion.coremodule.VisitList.domain.VisitStatus; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public record TotalOrder( | ||
String pickUpRoute, | ||
String visitHour, | ||
String visitMin, | ||
String userName, | ||
VisitStatus orderStatus, | ||
LocalDateTime createdAt, | ||
String orderNum, | ||
List<MenuOrder> menu, | ||
Integer totalPrice | ||
) { | ||
} |
112 changes: 112 additions & 0 deletions
112
...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,112 @@ | ||
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.AddMenu; | ||
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.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
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 (정후) | ||
@PostMapping("/{storeId}/{orderId}/preparing") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "주문 접숙하기", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "주문 접수 API", description = "주문 접수 API 입니다.") | ||
public ApplicationResponse<String> changeToPreparing( | ||
@PathVariable Long storeId, | ||
@PathVariable Long orderId | ||
) { | ||
|
||
customerSaveUseCase.changeToPreparing(storeId, orderId); | ||
return ApplicationResponse.ok("주문을 접수했습니다."); | ||
} | ||
|
||
// 준비 완료 시키는 API (정후) | ||
@PostMapping("/{storeId}/{orderId}/prepared") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "주문 준비 완료", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "주문 준비 완료 API", description = "주문 준비 완료 API 입니다.") | ||
public ApplicationResponse<String> changeToPrepared( | ||
@PathVariable Long storeId, | ||
@PathVariable Long orderId | ||
) { | ||
|
||
customerSaveUseCase.changeToPrepared(storeId, orderId); | ||
return ApplicationResponse.ok("주문을 준비 완료했습니다."); | ||
} | ||
|
||
// 메뉴 추가 API | ||
@PostMapping("/{storeId}/addmenu") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "메뉴 추가 완료", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "메뉴 추가 완료 API", description = "메뉴 추가 완료 API 입니다.") | ||
public ApplicationResponse<String> addMenuInfo( | ||
@PathVariable Long storeId, | ||
@RequestPart(value = "dto") AddMenu addMenu, | ||
@RequestPart(value = "file") MultipartFile multipartFile) { | ||
|
||
customerSaveUseCase.addMenuInfo(storeId, addMenu, multipartFile); | ||
return ApplicationResponse.ok("메뉴 추가가 완료 되었습니다."); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.