diff --git a/src/main/java/com/jangburich/domain/order/application/OrderService.java b/src/main/java/com/jangburich/domain/order/application/OrderService.java index 8e9a5a8..bf59b26 100644 --- a/src/main/java/com/jangburich/domain/order/application/OrderService.java +++ b/src/main/java/com/jangburich/domain/order/application/OrderService.java @@ -5,6 +5,7 @@ import com.jangburich.domain.menu.domain.Menu; import com.jangburich.domain.menu.domain.repository.MenuRepository; import com.jangburich.domain.order.domain.Cart; +import com.jangburich.domain.order.domain.OrderStatus; import com.jangburich.domain.order.domain.Orders; import com.jangburich.domain.order.domain.repository.CartRepository; import com.jangburich.domain.order.domain.repository.OrdersRepository; @@ -171,6 +172,7 @@ private Orders saveOrder(User user, Store store, Team team, OrderRequest orderRe .store(store) .user(user) .team(team) + .orderStatus(OrderStatus.RECEIVED) .build(); return ordersRepository.save(orders); } @@ -179,6 +181,7 @@ private void associateCartsWithOrder(List carts, Orders orders) { carts.forEach(cart -> cart.updateOrders(orders)); } + @Transactional public Message useMealTicket(String userProviderId, Long orderId) { User user = userRepository.findByProviderId(userProviderId) .orElseThrow(() -> new NullPointerException()); @@ -188,7 +191,7 @@ public Message useMealTicket(String userProviderId, Long orderId) { orders.validateUser(user); - orders.updateStatus(Status.INACTIVE); + orders.updateOrderStatus(OrderStatus.TICKET_USED); return Message.builder() .message("식권을 사용했습니다.") diff --git a/src/main/java/com/jangburich/domain/order/domain/OrderStatus.java b/src/main/java/com/jangburich/domain/order/domain/OrderStatus.java new file mode 100644 index 0000000..05780ce --- /dev/null +++ b/src/main/java/com/jangburich/domain/order/domain/OrderStatus.java @@ -0,0 +1,7 @@ +package com.jangburich.domain.order.domain; + +public enum OrderStatus { + RECEIVED, // 주문 접수됨, 식권 발급 완료된 상태 + TICKET_USED, // 식권 사용 완료 + CANCELLED // 주문 취소됨 +} diff --git a/src/main/java/com/jangburich/domain/order/domain/Orders.java b/src/main/java/com/jangburich/domain/order/domain/Orders.java index 621f0a9..eef2f73 100644 --- a/src/main/java/com/jangburich/domain/order/domain/Orders.java +++ b/src/main/java/com/jangburich/domain/order/domain/Orders.java @@ -6,6 +6,8 @@ import com.jangburich.domain.user.domain.User; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -39,12 +41,21 @@ public class Orders extends BaseEntity { @JoinColumn(name = "team_id") private Team team; + @Enumerated(EnumType.STRING) + @Column(name = "order_status") + private OrderStatus orderStatus; + @Builder - public Orders(Store store, User user, Team team) { + public Orders(Store store, User user, Team team, OrderStatus orderStatus) { this.store = store; this.user = user; this.team = team; + this.orderStatus = orderStatus; + } + + public void updateOrderStatus(OrderStatus orderStatus) { + this.orderStatus = orderStatus; } public void validateUser(User user) { diff --git a/src/main/java/com/jangburich/domain/order/presentation/OrderController.java b/src/main/java/com/jangburich/domain/order/presentation/OrderController.java index 8a13196..213a6b2 100644 --- a/src/main/java/com/jangburich/domain/order/presentation/OrderController.java +++ b/src/main/java/com/jangburich/domain/order/presentation/OrderController.java @@ -53,7 +53,7 @@ public ResponseCustom order( } @Operation(summary = "식권 사용", description = "식권을 사용합니다.") - @PostMapping("/tickets") + @PostMapping("/tickets/{orderId}") public ResponseCustom useMealTicket( Authentication authentication, @PathVariable Long orderId