Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.example.Centralthon.domain.order.service;

import com.example.Centralthon.domain.order.web.dto.OrderReq;
import com.example.Centralthon.domain.order.web.dto.OrderRes;

import java.util.List;
import com.example.Centralthon.domain.order.web.dto.CreateOrderReq;
import com.example.Centralthon.domain.order.web.dto.CreateOrderRes;

public interface OrderService {
OrderRes orderMenus(OrderReq orderReq);
CreateOrderRes orderMenus(CreateOrderReq orderReq);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import com.example.Centralthon.domain.order.exception.CodeNotCreatedException;
import com.example.Centralthon.domain.order.repository.OrderItemRepository;
import com.example.Centralthon.domain.order.repository.OrderRepository;
import com.example.Centralthon.domain.order.web.dto.CreateOrderReq;
import com.example.Centralthon.domain.order.web.dto.CreateOrderRes;
import com.example.Centralthon.domain.order.web.dto.OrderItemListReq;
import com.example.Centralthon.domain.order.web.dto.OrderReq;
import com.example.Centralthon.domain.order.web.dto.OrderRes;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
Expand All @@ -37,7 +37,7 @@ public class OrderServiceImpl implements OrderService {

@Override
@Transactional
public OrderRes orderMenus(OrderReq orderReq) {
public CreateOrderRes orderMenus(CreateOrderReq orderReq) {
Map<Long, Integer> orderList = new HashMap<>();

for (OrderItemListReq orderItemListReq : orderReq.getItems()) {
Expand All @@ -60,13 +60,15 @@ public OrderRes orderMenus(OrderReq orderReq) {
Order order = createOrderWithUniqueCode(totalPrice);

List<OrderItem> orderItemList = new ArrayList<>();
List<Long> storeIdList = new ArrayList<>();
for(Menu menu : menuList) {
OrderItem orderItem = OrderItem.toEntity(order, menu, orderList.get(menu.getId()));
orderItemList.add(orderItem);
if(!storeIdList.contains(menu.getStore().getId())) storeIdList.add(menu.getStore().getId());
}
orderItemRepository.saveAll(orderItemList);

return OrderRes.from(order);
return CreateOrderRes.of(order, storeIdList);
}

private Order createOrderWithUniqueCode(int totalPrice) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.Centralthon.domain.order.web.controller;

import com.example.Centralthon.domain.order.service.OrderService;
import com.example.Centralthon.domain.order.web.dto.OrderReq;
import com.example.Centralthon.domain.order.web.dto.OrderRes;
import com.example.Centralthon.domain.order.web.dto.CreateOrderReq;
import com.example.Centralthon.domain.order.web.dto.CreateOrderRes;
import com.example.Centralthon.global.response.SuccessResponse;
import com.example.Centralthon.global.response.code.SuccessResponseCode;
import jakarta.validation.Valid;
Expand All @@ -18,8 +18,8 @@ public class OrderController {
private final OrderService orderService;

@PostMapping
public ResponseEntity<SuccessResponse<OrderRes>> createOrder(@RequestBody @Valid OrderReq orderReq) {
OrderRes orderRes = orderService.orderMenus(orderReq);
return ResponseEntity.status(HttpStatus.CREATED).body(SuccessResponse.of(orderRes, SuccessResponseCode.SUCCESS_CREATED));
public ResponseEntity<SuccessResponse<CreateOrderRes>> createOrder(@RequestBody @Valid CreateOrderReq orderReq) {
CreateOrderRes createOrderRes = orderService.orderMenus(orderReq);
return ResponseEntity.status(HttpStatus.CREATED).body(SuccessResponse.of(createOrderRes, SuccessResponseCode.SUCCESS_CREATED));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Getter
@Setter
public class OrderReq {
public class CreateOrderReq {
@NotEmpty(message = "주문 항목은 빈 배열일 수 없습니다.")
List<@Valid OrderItemListReq> items;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.Centralthon.domain.order.web.dto;

import com.example.Centralthon.domain.order.entity.Order;

import java.util.List;

public record CreateOrderRes(
String code,
List<Long> storeList
) {
public static CreateOrderRes of(Order order, List<Long> storeList) {
return new CreateOrderRes(order.getPickUpCode(), storeList);
}
}

This file was deleted.