Skip to content

Commit

Permalink
πŸš€ :: Api-v0.0.6
Browse files Browse the repository at this point in the history
πŸš€ :: Api-v0.0.6
  • Loading branch information
ImNM authored Jan 24, 2023
2 parents 3b29066 + 312cc29 commit 2ce28e9
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ public class DoneOrderEvent extends DomainEvent {

@Nullable private final String paymentKey;

private final Long itemId;

public static DoneOrderEvent from(Order order) {
return DoneOrderEvent.builder()
.orderMethod(order.getOrderMethod())
.paymentKey(order.isNeedPaid() ? order.getPaymentKey() : null)
.userId(order.getUserId())
.orderUuid(order.getUuid())
.itemId(order.getItemId())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class WithDrawOrderEvent extends DomainEvent {
private final OrderStatus orderStatus;

@Nullable private final String paymentKey;
private final Long itemId;

public static WithDrawOrderEvent from(Order order) {
return WithDrawOrderEvent.builder()
Expand All @@ -27,6 +28,7 @@ public static WithDrawOrderEvent from(Order order) {
.userId(order.getUserId())
.orderUuid(order.getUuid())
.orderStatus(order.getOrderStatus())
.itemId(order.getItemId())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import band.gosrock.common.annotation.DomainService;
import band.gosrock.domain.common.aop.redissonLock.RedissonLock;
import band.gosrock.domain.common.vo.IssuedTicketInfoVo;
import band.gosrock.domain.domains.event.adaptor.EventAdaptor;
import band.gosrock.domain.domains.event.exception.HostNotAuthEventException;
import band.gosrock.domain.domains.issuedTicket.adaptor.IssuedTicketAdaptor;
import band.gosrock.domain.domains.issuedTicket.adaptor.IssuedTicketOptionAnswerAdaptor;
import band.gosrock.domain.domains.issuedTicket.domain.IssuedTicket;
import band.gosrock.domain.domains.issuedTicket.dto.request.CreateIssuedTicketDTO;
import band.gosrock.domain.domains.issuedTicket.dto.response.CreateIssuedTicketResponse;
import band.gosrock.domain.domains.issuedTicket.repository.IssuedTicketRepository;
import band.gosrock.domain.domains.ticket_item.domain.TicketItem;
import band.gosrock.domain.domains.order.adaptor.OrderAdaptor;
import band.gosrock.domain.domains.order.domain.Order;
import band.gosrock.domain.domains.user.adaptor.UserAdaptor;
import band.gosrock.domain.domains.user.domain.User;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,27 +22,13 @@
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class IssuedTicketDomainService {

private final IssuedTicketRepository issuedTicketRepository;
private final IssuedTicketAdaptor issuedTicketAdaptor;
private final IssuedTicketOptionAnswerAdaptor issuedTicketOptionAnswerAdaptor;
private final EventAdaptor eventAdaptor;

@RedissonLock(LockName = "ν‹°μΌ“μž¬κ³ κ΄€λ¦¬", paramClassType = TicketItem.class, identifier = "id")
@Transactional
public void createIssuedTicket(
TicketItem ticketItem, List<CreateIssuedTicketDTO> createIssuedTicketDTOs) {
createIssuedTicketDTOs.forEach(
dto -> {
CreateIssuedTicketResponse responseDTO =
IssuedTicket.orderLineItemToIssuedTickets(dto);
issuedTicketAdaptor.saveAll(responseDTO.getIssuedTickets());
});
}
private final UserAdaptor userAdaptor;
private final OrderAdaptor orderAdaptor;

@RedissonLock(LockName = "ν‹°μΌ“μž¬κ³ κ΄€λ¦¬", paramClassType = TicketItem.class, identifier = "id")
@RedissonLock(LockName = "ν‹°μΌ“μž¬κ³ κ΄€λ¦¬", identifier = "itemId")
@Transactional
public void withDrawIssuedTicket(TicketItem ticketItem, List<IssuedTicket> issuedTickets) {
public void withDrawIssuedTicket(Long itemId, List<IssuedTicket> issuedTickets) {
issuedTickets.forEach(
issuedTicket -> {
issuedTicket.getTicketItem().increaseQuantity(1L);
Expand All @@ -60,4 +46,22 @@ public IssuedTicketInfoVo processingEntranceIssuedTicket(
issuedTicket.entrance();
return issuedTicket.toIssuedTicketInfoVo();
}

@RedissonLock(LockName = "ν‹°μΌ“μž¬κ³ κ΄€λ¦¬", identifier = "itemId")
public void createIssuedTicket(Long itemId, String orderUuid, Long userId) {
User user = userAdaptor.queryUser(userId);
Order order = orderAdaptor.findByOrderUuid(orderUuid);

List<CreateIssuedTicketDTO> createIssuedTicketDTOS =
order.getOrderLineItems().stream()
.map(orderLineItem -> new CreateIssuedTicketDTO(order, orderLineItem, user))
.toList();

createIssuedTicketDTOS.forEach(
dto -> {
CreateIssuedTicketResponse responseDTO =
IssuedTicket.orderLineItemToIssuedTickets(dto);
issuedTicketAdaptor.saveAll(responseDTO.getIssuedTickets());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@


import band.gosrock.domain.common.events.order.DoneOrderEvent;
import band.gosrock.domain.domains.issuedTicket.dto.request.CreateIssuedTicketDTO;
import band.gosrock.domain.domains.issuedTicket.service.IssuedTicketDomainService;
import band.gosrock.domain.domains.order.adaptor.OrderAdaptor;
import band.gosrock.domain.domains.order.domain.Order;
import band.gosrock.domain.domains.user.adaptor.UserAdaptor;
import band.gosrock.domain.domains.user.domain.User;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
Expand All @@ -22,22 +17,17 @@ public class OrderEventHandler {

private final IssuedTicketDomainService issuedTicketDomainService;

private final UserAdaptor userAdaptor;

private final OrderAdaptor orderAdaptor;

@TransactionalEventListener(
classes = DoneOrderEvent.class,
phase = TransactionPhase.BEFORE_COMMIT)
public void handleDoneOrderEvent(DoneOrderEvent doneOrderEvent) {
log.info(doneOrderEvent.getOrderUuid() + "μ£Όλ¬Έ μƒνƒœ μ™„λ£Œ, ν‹°μΌ“ μƒμ„±μž‘μ—… 진행");
User user = userAdaptor.queryUser(doneOrderEvent.getUserId());
Order order = orderAdaptor.findByOrderUuid(doneOrderEvent.getOrderUuid());
List<CreateIssuedTicketDTO> createIssuedTicketDTOS =
order.getOrderLineItems().stream()
.map(orderLineItem -> new CreateIssuedTicketDTO(order, orderLineItem, user))
.toList();
issuedTicketDomainService.createIssuedTicket(order.getItem(), createIssuedTicketDTOS);
issuedTicketDomainService.createIssuedTicket(
doneOrderEvent.getItemId(),
doneOrderEvent.getOrderUuid(),
doneOrderEvent.getUserId());
log.info(doneOrderEvent.getOrderUuid() + "μ£Όλ¬Έ μƒνƒœ μ™„λ£Œ, ν‹°μΌ“ μƒμ„±μž‘μ—… μ™„λ£Œ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import band.gosrock.domain.domains.issuedTicket.adaptor.IssuedTicketAdaptor;
import band.gosrock.domain.domains.issuedTicket.domain.IssuedTicket;
import band.gosrock.domain.domains.issuedTicket.service.IssuedTicketDomainService;
import band.gosrock.domain.domains.order.adaptor.OrderAdaptor;
import band.gosrock.domain.domains.order.domain.Order;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -23,17 +21,15 @@ public class WithDrawOrderEventHandler {

private final IssuedTicketAdaptor issuedTicketAdaptor;

private final OrderAdaptor orderAdaptor;

@TransactionalEventListener(
classes = WithDrawOrderEventHandler.class,
classes = WithDrawOrderEvent.class,
phase = TransactionPhase.BEFORE_COMMIT)
public void handleWithDrawOrderEvent(WithDrawOrderEvent withDrawOrderEvent) {
log.info(withDrawOrderEvent.getOrderUuid() + "μ£Όλ¬Έ μƒνƒœ 철회 , ν‹°μΌ“ 제거 ν•„μš”");
Order order = orderAdaptor.findByOrderUuid(withDrawOrderEvent.getOrderUuid());
log.info(withDrawOrderEvent.getOrderUuid() + "μ£Όλ¬Έ μƒνƒœ 철회 , ν‹°μΌ“ 철회 ν•„μš”");
List<IssuedTicket> issuedTickets =
issuedTicketAdaptor.findAllByOrderUuid(withDrawOrderEvent.getOrderUuid());
issuedTicketDomainService.withDrawIssuedTicket(order.getItem(), issuedTickets);
log.info(withDrawOrderEvent.getOrderUuid() + "μ£Όλ¬Έ μƒνƒœ μ™„λ£Œ, ν‹°μΌ“ μƒμ„±μž‘μ—… μ™„λ£Œ");
issuedTicketDomainService.withDrawIssuedTicket(
withDrawOrderEvent.getItemId(), issuedTickets);
log.info(withDrawOrderEvent.getOrderUuid() + "μ£Όλ¬Έ μƒνƒœ μ™„λ£Œ, ν‹°μΌ“ 철회 μ™„λ£Œ");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ public TicketItem getItem() {
return getOrderLineItem().getTicketItem();
}

public Long getItemId() {
return getOrderLineItem().getTicketItem().getId();
}

/** μ£Όλ¬Έμ—μ„œ ν‹°μΌ“ μƒν’ˆμ˜ νƒ€μž…μ„ λ°˜ν™˜ν•©λ‹ˆλ‹€. */
public TicketType getItemType() {
return getItem().getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import band.gosrock.domain.domains.order.domain.OrderLineItem;
import band.gosrock.domain.domains.order.domain.OrderMethod;
import band.gosrock.domain.domains.order.domain.OrderStatus;
import band.gosrock.domain.domains.ticket_item.domain.TicketItem;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -31,6 +32,7 @@ class OrderApproveServiceConcurrencyFailTest {
@Autowired OrderApproveService orderApproveService;

@Mock OrderLineItem orderLineItem;
@Mock TicketItem ticketItem;

@MockBean OrderAdaptor orderAdaptor;

Expand All @@ -39,6 +41,8 @@ class OrderApproveServiceConcurrencyFailTest {
@BeforeEach
void setUp() {
given(orderLineItem.isNeedPaid()).willReturn(Boolean.FALSE);
given(orderLineItem.getTicketItem()).willReturn(ticketItem);
given(ticketItem.getId()).willReturn(1L);
order =
Order.builder()
.orderMethod(OrderMethod.APPROVAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import band.gosrock.domain.domains.order.domain.OrderLineItem;
import band.gosrock.domain.domains.order.domain.OrderMethod;
import band.gosrock.domain.domains.order.domain.OrderStatus;
import band.gosrock.domain.domains.ticket_item.domain.TicketItem;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -33,14 +34,16 @@ class OrderApproveServiceConcurrencyTest {
@Autowired RedissonClient redissonClient;

@Mock OrderLineItem orderLineItem;

@MockBean private OrderAdaptor orderAdaptor;

@Mock TicketItem ticketItem;
Order order;

@BeforeEach
void setUp() {
given(orderLineItem.isNeedPaid()).willReturn(Boolean.FALSE);
given(orderLineItem.getTicketItem()).willReturn(ticketItem);
given(ticketItem.getId()).willReturn(1L);
order =
Order.builder()
.orderMethod(OrderMethod.APPROVAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
import band.gosrock.domain.DomainIntegrateSpringBootTest;
import band.gosrock.domain.domains.order.adaptor.OrderAdaptor;
import band.gosrock.domain.domains.order.domain.Order;
import band.gosrock.domain.domains.order.domain.OrderLineItem;
import band.gosrock.domain.domains.order.domain.OrderStatus;
import band.gosrock.domain.domains.ticket_item.domain.TicketItem;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;

Expand All @@ -27,6 +30,8 @@ class WithdrawOrderServiceTest {
@Autowired WithdrawOrderService withdrawOrderService;

@MockBean OrderAdaptor orderAdaptor;
@Mock OrderLineItem orderLineItem;
@Mock TicketItem ticketItem;

Order order;

Expand All @@ -38,10 +43,13 @@ void setUp() {
Order.builder()
.userId(userId)
.orderStatus(OrderStatus.CONFIRM)
.orderLineItems(List.of())
.orderLineItems(List.of(orderLineItem))
.build();
order.addUUID();
given(orderAdaptor.findByOrderUuid(any())).willReturn(order);
given(orderLineItem.getTicketItem()).willReturn(ticketItem);
given(orderLineItem.canRefund()).willReturn(Boolean.TRUE);
given(ticketItem.getId()).willReturn(1L);
}

@Test
Expand Down

0 comments on commit 2ce28e9

Please sign in to comment.