Skip to content

Commit

Permalink
Merge pull request #71 from connecSWUn/fix/complete-order
Browse files Browse the repository at this point in the history
[FEAT] 메뉴 별 주문 상태 수정 API 구현
  • Loading branch information
ehBeak authored Aug 7, 2023
2 parents dcd4cae + 1d20dfa commit c748c51
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.swulab.eatswunee.domain.ordermenu.adpater.in.web.controller;

import com.swulab.eatswunee.domain.ordermenu.adpater.in.web.dto.request.UpdateOrderMenuStatusRequest;
import com.swulab.eatswunee.domain.ordermenu.adpater.in.web.dto.response.UpdateOrderMenuStatusResponse;
import com.swulab.eatswunee.domain.ordermenu.application.port.in.UpdateOrderMenuStatusUseCase;
import com.swulab.eatswunee.domain.ordermenu.application.port.in.command.UpdateOrderMenuStatusCommand;
import com.swulab.eatswunee.global.common.adapter.web.in.dto.SuccessResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class UpdateOrderMenuStatusController {

public final UpdateOrderMenuStatusUseCase updateOrderMenuStatusUseCase;

@PatchMapping("/orderMenu/orderMenuStatus")
public ResponseEntity updateOrderMenuStatus(@RequestBody UpdateOrderMenuStatusRequest request) {

UpdateOrderMenuStatusCommand command = updateOrderMenuStatusUseCase.updateOrderMenuStatus(request.getOrderMenuId(), request.getOrderMenuStatus());
UpdateOrderMenuStatusResponse response = new UpdateOrderMenuStatusResponse(command);

return ResponseEntity.ok(SuccessResponse.create200SuccessResponse(response));



}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.swulab.eatswunee.domain.ordermenu.adpater.in.web.dto.request;

import com.swulab.eatswunee.domain.ordermenu.domain.model.OrderMenuStatus;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Getter
@Slf4j
public class UpdateOrderMenuStatusRequest {

public Long orderMenuId;
public OrderMenuStatus orderMenuStatus;

public UpdateOrderMenuStatusRequest(Long orderMenuId, OrderMenuStatus orderMenuStatus) {

this.orderMenuId = orderMenuId;
this.orderMenuStatus = orderMenuStatus;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.swulab.eatswunee.domain.ordermenu.adpater.in.web.dto.response;

import com.swulab.eatswunee.domain.ordermenu.application.port.in.command.UpdateOrderMenuStatusCommand;
import com.swulab.eatswunee.domain.ordermenu.domain.model.OrderMenuStatus;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class UpdateOrderMenuStatusResponse {

private Long order_menu_id;
private OrderMenuStatus to_order_menu_status;

public UpdateOrderMenuStatusResponse(UpdateOrderMenuStatusCommand command) {
this.order_menu_id = command.getOrderMenuId();
this.to_order_menu_status = command.getOrderMenuStatus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public OrderMenu mapToDomainEntity(OrderMenuJpaEntity orderMenuJpaEntity) {
return OrderMenu.builder()
.orderMenuId(orderMenuJpaEntity.getOrderMenuId())
.menuCnt(orderMenuJpaEntity.getMenuCnt())
.orderMenuStatus(orderMenuJpaEntity.getOrderMenuStatus())
.menu(menuMapper.mapToDomainEntity(orderMenuJpaEntity.getMenuJpaEntity()))
.order(orderMapper.mapToDomainEntity(orderMenuJpaEntity.getOrderJpaEntity()))
.build();
Expand All @@ -28,6 +29,7 @@ public OrderMenuJpaEntity mapToJpaEntity(OrderMenu orderMenu) {
return OrderMenuJpaEntity.builder()
.orderMenuId(orderMenu.getOrderMenuId())
.menuCnt(orderMenu.getMenuCnt())
.orderMenuStatus(orderMenu.getOrderMenuStatus())
// .orderPrice(orderMenu.getOrderPrice())
.menuJpaEntity(menuMapper.mapToJpaEntity(orderMenu.getMenu()))
.orderJpaEntity(orderMapper.mapToJpaEntity(orderMenu.getOrder()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.swulab.eatswunee.domain.ordermenu.application.port.out.FindNowOrderListPort;
import com.swulab.eatswunee.domain.ordermenu.application.port.out.FindOrderMenuPort;
import com.swulab.eatswunee.domain.ordermenu.application.port.out.FindUserMenuOrderListPort;
import com.swulab.eatswunee.domain.ordermenu.application.port.out.SaveOrderMenuPort;
import com.swulab.eatswunee.domain.ordermenu.application.port.out.command.FindRestaurantOrderMenuCommand;
import com.swulab.eatswunee.domain.ordermenu.application.port.out.command.RestaurantNowOrderListCommand;
import com.swulab.eatswunee.domain.ordermenu.domain.model.OrderMenu;
Expand All @@ -19,7 +20,7 @@
@Component
@RequiredArgsConstructor
public class OrderMenuPersistenceAdapter implements FindOrderMenuPort ,
FindUserMenuOrderListPort, FindNowOrderListPort, FindCompletedOrderListPort {
FindUserMenuOrderListPort, FindNowOrderListPort, FindCompletedOrderListPort, SaveOrderMenuPort {

private final OrderMenuQueryRepository orderMenuQueryRepository;
private final OrderMenuJpaRepository orderMenuJpaRepository;
Expand Down Expand Up @@ -55,6 +56,13 @@ public List<RestaurantNowOrderListCommand> findNowOrderList(Long restaurantId) {
public List<RestaurantNowOrderListCommand> findCompletedOrderList(Long restaurantId) {
return orderMenuQueryRepository.findRestaurantCompletedOrder(restaurantId);
}

@Override
public OrderMenu saveOrderMenu(OrderMenu orderMenu) {
OrderMenuJpaEntity orderMenuJpaEntity = orderMenuMapper.mapToJpaEntity(orderMenu);
OrderMenu savedOrderMenu = orderMenuMapper.mapToDomainEntity(orderMenuJpaRepository.save(orderMenuJpaEntity));
return savedOrderMenu;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.swulab.eatswunee.domain.menu.adapter.out.persistence.jpa.model.MenuJpaEntity;
import com.swulab.eatswunee.domain.order.adapter.out.persistence.jpa.model.OrderJpaEntity;
import com.swulab.eatswunee.domain.ordermenu.domain.model.OrderMenuStatus;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand All @@ -26,6 +29,9 @@ public class OrderMenuJpaEntity {

private int menuCnt;

@Enumerated(EnumType.STRING)
private OrderMenuStatus orderMenuStatus;

// private Integer orderPrice;

@ManyToOne
Expand All @@ -37,11 +43,12 @@ public class OrderMenuJpaEntity {
private OrderJpaEntity orderJpaEntity;

@Builder
public OrderMenuJpaEntity(Long orderMenuId, int menuCnt, Integer orderPrice,
public OrderMenuJpaEntity(Long orderMenuId, int menuCnt, OrderMenuStatus orderMenuStatus, Integer orderPrice,
MenuJpaEntity menuJpaEntity,
OrderJpaEntity orderJpaEntity) {
this.orderMenuId = orderMenuId;
this.menuCnt = menuCnt;
this.orderMenuStatus = orderMenuStatus;
// this.orderPrice = orderPrice;
this.menuJpaEntity = menuJpaEntity;
this.orderJpaEntity = orderJpaEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.swulab.eatswunee.domain.ordermenu.application.port.in;

import com.swulab.eatswunee.domain.ordermenu.application.port.in.command.UpdateOrderMenuStatusCommand;
import com.swulab.eatswunee.domain.ordermenu.domain.model.OrderMenuStatus;

public interface UpdateOrderMenuStatusUseCase {

UpdateOrderMenuStatusCommand updateOrderMenuStatus(Long orderMenuId, OrderMenuStatus orderMenuStatus);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.swulab.eatswunee.domain.ordermenu.application.port.in.command;

import com.swulab.eatswunee.domain.ordermenu.domain.model.OrderMenuStatus;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class UpdateOrderMenuStatusCommand {

private Long orderMenuId;
private OrderMenuStatus orderMenuStatus;

public UpdateOrderMenuStatusCommand(Long orderMenuId,
OrderMenuStatus orderMenuStatus) {
this.orderMenuId = orderMenuId;
this.orderMenuStatus = orderMenuStatus;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.swulab.eatswunee.domain.ordermenu.application.port.out;

import com.swulab.eatswunee.domain.ordermenu.domain.model.OrderMenu;

public interface SaveOrderMenuPort {

OrderMenu saveOrderMenu(OrderMenu orderMenu);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.swulab.eatswunee.domain.ordermenu.application.service;

import com.swulab.eatswunee.domain.ordermenu.application.port.in.UpdateOrderMenuStatusUseCase;
import com.swulab.eatswunee.domain.ordermenu.application.port.in.command.UpdateOrderMenuStatusCommand;
import com.swulab.eatswunee.domain.ordermenu.application.port.out.FindOrderMenuPort;
import com.swulab.eatswunee.domain.ordermenu.application.port.out.SaveOrderMenuPort;
import com.swulab.eatswunee.domain.ordermenu.domain.model.OrderMenu;
import com.swulab.eatswunee.domain.ordermenu.domain.model.OrderMenuStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class UpdateOrderMenuService implements UpdateOrderMenuStatusUseCase {

private final FindOrderMenuPort findOrderMenuPort;
private final SaveOrderMenuPort saveOrderMenuPort;

@Override
public UpdateOrderMenuStatusCommand updateOrderMenuStatus(Long orderMenuId, OrderMenuStatus orderMenuStatus) {

OrderMenu orderMenu = findOrderMenuPort.findOrderMenuPort(orderMenuId);
orderMenu.changeOrderMenuStatusTo(orderMenuStatus);
OrderMenu savedOrderMenu = saveOrderMenuPort.saveOrderMenu(orderMenu);

return new UpdateOrderMenuStatusCommand(savedOrderMenu.getOrderMenuId(), savedOrderMenu.getOrderMenuStatus());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ public class OrderMenu {

private Long orderMenuId;
private int menuCnt;
// private Integer orderPrice; // 주문 가격
private OrderMenuStatus orderMenuStatus;

private Menu menu;
private Order order;

@Builder
public OrderMenu(Long orderMenuId, int menuCnt, Integer orderPrice,
public OrderMenu(Long orderMenuId, int menuCnt, OrderMenuStatus orderMenuStatus, Integer orderPrice,
Menu menu, Order order) {
this.orderMenuId = orderMenuId;
this.menuCnt = menuCnt;
this.orderMenuStatus = orderMenuStatus;
// this.orderPrice = orderPrice;
this.menu = menu;
this.order = order;
}

public void changeOrderMenuStatusTo(OrderMenuStatus orderMenuStatus) {
this.orderMenuStatus = orderMenuStatus;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.swulab.eatswunee.domain.ordermenu.domain.model;

public enum OrderMenuStatus {

ONGOING, COMPLETED;

}
2 changes: 0 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ spring:
- localdb
- s3
- jwt-local
- port
dev:
- devdb
- s3
- jwt-dev
- port
pid:
file: /home/ubuntu/swulab/eatswunee/eatswunee.pid

Expand Down

0 comments on commit c748c51

Please sign in to comment.