Skip to content

Commit

Permalink
feat : 두둥 티켓 적용 (#361)
Browse files Browse the repository at this point in the history
* feat : 두둥 티켓 적용

* style : 오타 수정
  • Loading branch information
ImNM authored Feb 15, 2023
1 parent bf48c69 commit 10ca04c
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
package band.gosrock.api.common.aop.hostRole;


import lombok.RequiredArgsConstructor;
import band.gosrock.api.common.UserUtils;
import band.gosrock.domain.domains.event.adaptor.EventAdaptor;
import band.gosrock.domain.domains.host.adaptor.HostAdaptor;
import org.springframework.stereotype.Component;

@RequiredArgsConstructor
@Component
class HostCallTransactionFactory {

private final HostRoleEventTransaction hostRoleEventTransaction;
private final HostRoleEventTransaction hostRoleEventWithoutTransaction;

public HostCallTransactionFactory(
UserUtils userUtils,
HostAdaptor hostAdaptor,
EventAdaptor eventAdaptor,
HostRoleEventTransaction hostRoleEventTransaction,
HostRoleHostTransaction hostRoleHostTransaction) {
this.hostRoleEventTransaction = hostRoleEventTransaction;
this.hostRoleEventWithoutTransaction =
new HostRoleEventTransaction(userUtils, eventAdaptor, hostAdaptor);
this.hostRoleHostTransaction = hostRoleHostTransaction;
this.hostRoleHostWithoutTransaction = new HostRoleHostTransaction(userUtils, hostAdaptor);
}

private final HostRoleHostTransaction hostRoleHostTransaction;
private final HostRoleHostTransaction hostRoleHostWithoutTransaction;

public HostRoleCallTransaction getCallTransaction(FindHostFrom findHostFrom) {
public HostRoleCallTransaction getCallTransaction(
FindHostFrom findHostFrom, Boolean applyTransaction) {
if (findHostFrom == FindHostFrom.HOST_ID) {
return hostRoleHostTransaction;
return applyTransaction ? hostRoleHostTransaction : hostRoleHostWithoutTransaction;
}
return hostRoleEventTransaction;
return applyTransaction ? hostRoleEventTransaction : hostRoleEventWithoutTransaction;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Object aop(final ProceedingJoinPoint joinPoint) throws Throwable {
Long id = getId(parameterNames, args, identifier);

return hostCallTransactionFactory
.getCallTransaction(findHostFrom)
.getCallTransaction(findHostFrom, annotation.applyTransaction())
.proceed(id, hostQualification, joinPoint);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ class HostRoleEventTransaction implements HostRoleCallTransaction {
@Transactional(readOnly = true)
public Object proceed(Long eventId, HostQualification role, final ProceedingJoinPoint joinPoint)
throws Throwable {
validRole(eventId, role);
return joinPoint.proceed();
}

private void validRole(Long eventId, HostQualification role) {
Long currentUserId = userUtils.getCurrentUserId();
Event event = eventAdaptor.findById(eventId);
Host host = hostAdaptor.findById(event.getHostId());
role.validQualification(currentUserId, host);
return joinPoint.proceed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ class HostRoleHostTransaction implements HostRoleCallTransaction {
@Transactional(readOnly = true)
public Object proceed(Long hostId, HostQualification role, final ProceedingJoinPoint joinPoint)
throws Throwable {
validRole(hostId, role);
return joinPoint.proceed();
}

private void validRole(Long hostId, HostQualification role) {
Long currentUserId = userUtils.getCurrentUserId();
Host host = hostAdaptor.findById(hostId);
role.validQualification(currentUserId, host);
return joinPoint.proceed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
HostQualification role();

FindHostFrom findHostFrom();

boolean applyTransaction() default true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import band.gosrock.domain.domains.order.domain.Order;
import band.gosrock.domain.domains.order.domain.OrderMethod;
import band.gosrock.domain.domains.ticket_item.domain.TicketItem;
import band.gosrock.domain.domains.ticket_item.domain.TicketPayType;
import band.gosrock.domain.domains.ticket_item.domain.TicketType;
import band.gosrock.domain.domains.user.domain.Profile;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -38,6 +39,12 @@ public class CreateOrderResponse {
@Schema(description = "티켓의 타입. 승인 , 선착순 두가지입니다.")
private final TicketType ticketType;

@Schema(description = "티켓의 지불 타입. 두둥티켓, 무료 , 유료 세가지입니다.")
private final TicketPayType ticketPayType;

@Schema(description = "계좌정보", nullable = true)
private final String accountNumber;

public static CreateOrderResponse from(Order order, TicketItem item, Profile profile) {
return CreateOrderResponse.builder()
.customerEmail(profile.getEmail())
Expand All @@ -48,6 +55,8 @@ public static CreateOrderResponse from(Order order, TicketItem item, Profile pro
.orderMethod(order.getOrderMethod())
.isNeedPayment(order.isNeedPaid())
.ticketType(item.getType())
.ticketPayType(item.getPayType())
.accountNumber(item.getAccountNumber())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ApproveOrderUseCase {

private final OrderMapper orderMapper;

@HostRolesAllowed(role = MANAGER, findHostFrom = EVENT_ID)
@HostRolesAllowed(role = MANAGER, findHostFrom = EVENT_ID, applyTransaction = false)
public OrderResponse execute(Long eventId, String orderUuid) {
String confirmOrderUuid = orderApproveService.execute(orderUuid);
return orderMapper.toOrderResponse(confirmOrderUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ public static Order createPaymentOrder(
/** 승인 결제인 주문을 생성합니다. */
public static Order createApproveOrder(
Long userId, Cart cart, TicketItem item, OrderValidator orderValidator) {
if (cart.isNeedPaid()) {
throw InvalidOrderException.EXCEPTION;
}
Order order =
Order.builder()
.userId(userId)
Expand All @@ -155,6 +152,7 @@ public static Order createApproveOrder(
.eventId(item.getEventId())
.build();
orderValidator.validCanCreate(order);
order.calculatePaymentInfo();
return order;
}

Expand Down Expand Up @@ -310,7 +308,7 @@ public Long getItemGroupId() {
/** 결제가 필요한 오더인지 반환합니다. */
public Boolean isNeedPaid() {
// 결제 여부는 총 결제금액으로 정함
return Money.ZERO.isLessThan(getTotalPaymentPrice());
return Money.ZERO.isLessThan(getTotalPaymentPrice()) && orderMethod.isPayment();
}

/** 결제 수단 정보를 가져옵니다. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import band.gosrock.domain.common.vo.Money;
import band.gosrock.domain.domains.coupon.domain.IssuedCoupon;
import band.gosrock.domain.domains.order.exception.LessThanMinmumPaymentOrderException;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -15,7 +16,10 @@
@Embeddable
@NoArgsConstructor
public class OrderCouponVo {

@Column(name = "coupon_name")
private String name = "사용하지 않음";

private Money discountAmount = Money.ZERO;
private Long couponId = ZERO;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import band.gosrock.domain.domains.order.domain.validator.OrderValidator;
import band.gosrock.domain.domains.ticket_item.adaptor.TicketItemAdaptor;
import band.gosrock.domain.domains.ticket_item.domain.TicketItem;
import band.gosrock.domain.domains.ticket_item.domain.TicketPayType;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -29,12 +30,23 @@ public class OrderFactory {
public Order createNormalOrder(Long cartId, Long userId) {
Cart cart = cartAdaptor.queryCart(cartId, userId);
TicketItem ticketItem = itemAdaptor.queryTicketItem(cart.getItemId());
// 결제 주문 생성
if (ticketItem.isFCFS()) {
return Order.createPaymentOrder(userId, cart, ticketItem, orderValidator);
TicketPayType payType = ticketItem.getPayType();
// 두둥티켓
if (payType == TicketPayType.DUDOONG_TICKET) {
return Order.createApproveOrder(userId, cart, ticketItem, orderValidator);
}
// 무료 티켓
if (payType == TicketPayType.FREE_TICKET) {
// 선착순 티켓
if (ticketItem.isFCFS()) {
return Order.createPaymentOrder(userId, cart, ticketItem, orderValidator);
}
// 승인 티켓
return Order.createApproveOrder(userId, cart, ticketItem, orderValidator);
}
// 승인 주문 생성
return Order.createApproveOrder(userId, cart, ticketItem, orderValidator);
// 유료 티켓
// 결제 주문 생성
return Order.createPaymentOrder(userId, cart, ticketItem, orderValidator);
}

public Order createCouponOrder(Long cartId, Long userId, Long couponId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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.order.domain.OrderStatus;
import band.gosrock.domain.domains.order.service.WithdrawPaymentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -37,6 +38,10 @@ public void handleDoneOrderFailEvent(DoneOrderEvent doneOrderEvent) {
log.info(doneOrderEvent.getOrderUuid() + "주문 실패 처리 핸들러");

Order order = orderAdaptor.findByOrderUuid(doneOrderEvent.getOrderUuid());
if (order.getOrderStatus() == OrderStatus.FAILED) {
return;
}

order.fail();

if (order.hasCoupon()) { // 쿠폰 사용했을 시 쿠폰 복구
Expand All @@ -47,7 +52,7 @@ public void handleDoneOrderFailEvent(DoneOrderEvent doneOrderEvent) {
issuedTicketDomainService.doneOrderEventAfterRollBackWithdrawIssuedTickets(
doneOrderEvent.getItemId(), doneOrderEvent.getOrderUuid());

if (order.isPaid()) {
if (order.isNeedPaid()) {
log.info(
doneOrderEvent.getOrderUuid()
+ ":"
Expand Down

0 comments on commit 10ca04c

Please sign in to comment.