Skip to content

Commit

Permalink
feat: 식권 사용 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
LEEJaeHyeok97 committed Nov 20, 2024
1 parent 163d698 commit 3de7376
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -179,6 +181,7 @@ private void associateCartsWithOrder(List<Cart> 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());
Expand All @@ -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("식권을 사용했습니다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.jangburich.domain.order.domain;

public enum OrderStatus {
RECEIVED, // 주문 접수됨, 식권 발급 완료된 상태
TICKET_USED, // 식권 사용 완료
CANCELLED // 주문 취소됨
}
13 changes: 12 additions & 1 deletion src/main/java/com/jangburich/domain/order/domain/Orders.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ResponseCustom<Message> order(
}

@Operation(summary = "식권 사용", description = "식권을 사용합니다.")
@PostMapping("/tickets")
@PostMapping("/tickets/{orderId}")
public ResponseCustom<Message> useMealTicket(
Authentication authentication,
@PathVariable Long orderId
Expand Down

0 comments on commit 3de7376

Please sign in to comment.