Skip to content

Commit

Permalink
Api-v0.1.5
Browse files Browse the repository at this point in the history
Api-v0.1.5
  • Loading branch information
ImNM authored Feb 15, 2023
2 parents 776e9f1 + 10ca04c commit e3c3ef5
Show file tree
Hide file tree
Showing 34 changed files with 963 additions and 143 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 @@ -3,9 +3,11 @@

import band.gosrock.domain.domains.host.domain.Host;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;

@Getter
@EqualsAndHashCode
@Builder
public class HostInfoVo {
private final Long hostId;
Expand All @@ -20,7 +22,7 @@ public class HostInfoVo {

private final String contactNumber;

private final boolean partner;
private final Boolean partner;

public static HostInfoVo from(Host host) {
return HostInfoVo.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

import band.gosrock.domain.domains.host.domain.Host;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;

@Getter
@EqualsAndHashCode
@Builder
public class HostProfileVo {
private final Long hostId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static IssuedTicketInfoVo from(IssuedTicket issuedTicket) {
.issuedTicketNo(issuedTicket.getIssuedTicketNo())
.uuid(issuedTicket.getUuid())
.ticketName(issuedTicket.getItemInfo().getTicketName())
.ticketPrice(issuedTicket.getPrice())
.ticketPrice(issuedTicket.getItemInfo().getPrice())
.createdAt(issuedTicket.getCreatedAt())
.issuedTicketStatus(issuedTicket.getIssuedTicketStatus())
.optionPrice(issuedTicket.sumOptionPrice())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package band.gosrock.domain.domains.host.domain;

import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;

import band.gosrock.domain.common.aop.domainEvent.Events;
import band.gosrock.domain.common.events.host.HostRegisterSlackEvent;
Expand Down Expand Up @@ -33,7 +35,7 @@ public class Host extends BaseTimeEntity {

// 파트너 여부
// 정책상 초기값 false 로 고정입니다
private final Boolean partner = false;
private final Boolean partner = FALSE;

// 슬랙 웹훅 url
private String slackUrl;
Expand Down Expand Up @@ -68,11 +70,6 @@ public HostUser getHostUserByUserId(Long userId) {
.orElseThrow(() -> HostUserNotFoundException.EXCEPTION);
}

public String getSlackToken() {
if (this.slackUrl == null) return null;
return this.slackUrl.substring(this.slackUrl.indexOf("https://hooks.slack.com/services/"));
}

public void updateProfile(HostProfile hostProfile) {
this.profile.updateProfile(hostProfile);
}
Expand Down Expand Up @@ -100,9 +97,8 @@ public Boolean isActiveHostUserId(Long userId) {

public void setHostUserRole(Long userId, HostRole role) {
// 마스터의 역할은 수정할 수 없음
if (this.getMasterUserId().equals(userId)) {
throw ForbiddenHostOperationException.EXCEPTION;
}
if (this.getMasterUserId().equals(userId))
throw CannotModifyMasterHostRoleException.EXCEPTION;
this.hostUsers.stream()
.filter(hostUser -> hostUser.getUserId().equals(userId))
.findFirst()
Expand All @@ -121,19 +117,17 @@ public void validateHostUserExistence(HostUser hostUser) {
validateHostUserIdExistence(hostUser.getUserId());
}

// todo :: 여기서부터 테스트 진행

/** 해당 유저가 호스트에 속하는지 확인하는 검증 로직입니다 */
public void validateHostUser(Long userId) {
if (!this.hasHostUserId(userId)) {
throw ForbiddenHostException.EXCEPTION;
}
if (!this.hasHostUserId(userId)) throw ForbiddenHostException.EXCEPTION;
}

/** 해당 유저가 호스트에 속하며 가입 승인을 완료했는지 (활성상태) 확인하는 검증 로직입니다 */
public void validateActiveHostUser(Long userId) {
this.validateHostUser(userId);
if (!this.isActiveHostUserId(userId)) {
throw NotAcceptedHostException.EXCEPTION;
}
if (!this.isActiveHostUserId(userId)) throw NotAcceptedHostException.EXCEPTION;
}

/** 해당 유저가 매니저 이상인지 확인하는 검증 로직입니다 */
Expand All @@ -147,16 +141,12 @@ public void validateManagerHostUser(Long userId) {
/** 해당 유저가 호스트의 마스터(담당자, 방장)인지 확인하는 검증 로직입니다 */
public void validateMasterHostUser(Long userId) {
this.validateActiveHostUser(userId);
if (!this.getMasterUserId().equals(userId)) {
throw NotMasterHostException.EXCEPTION;
}
if (!this.getMasterUserId().equals(userId)) throw NotMasterHostException.EXCEPTION;
}

/** 해당 호스트가 파트너 인지 검증합니다. */
public void validatePartnerHost() {
if (!partner) {
throw NotPartnerHostException.EXCEPTION;
}
if (partner != TRUE) throw NotPartnerHostException.EXCEPTION;
}

public HostInfoVo toHostInfoVo() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package band.gosrock.domain.domains.host.domain;

import static band.gosrock.domain.domains.host.domain.HostRole.GUEST;
import static java.lang.Boolean.FALSE;

import band.gosrock.domain.common.aop.domainEvent.Events;
import band.gosrock.domain.common.events.host.HostUserJoinEvent;
Expand Down Expand Up @@ -32,11 +34,11 @@ public class HostUser extends BaseTimeEntity {
private Long userId;

// 초대 승락 여부
private Boolean active = false;
private Boolean active = FALSE;

// 유저의 권한
@Enumerated(EnumType.STRING)
private HostRole role = HostRole.GUEST;
private HostRole role = GUEST;

public void setHostRole(HostRole role) {
this.role = role;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package band.gosrock.domain.domains.host.exception;


import band.gosrock.common.exception.DuDoongCodeException;

public class CannotModifyMasterHostRoleException extends DuDoongCodeException {
public static final DuDoongCodeException EXCEPTION = new CannotModifyMasterHostRoleException();

private CannotModifyMasterHostRoleException() {
super(HostErrorCode.CANNOT_MODIFY_MASTER_HOST_ROLE);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
import band.gosrock.domain.domains.issuedTicket.exception.CanNotCancelException;
import band.gosrock.domain.domains.issuedTicket.exception.CanNotEntranceException;
import band.gosrock.domain.domains.issuedTicket.exception.IssuedTicketAlreadyEntranceException;
import band.gosrock.domain.domains.order.domain.Order;
import band.gosrock.domain.domains.order.domain.OrderLineItem;
import band.gosrock.domain.domains.order.domain.OrderOptionAnswer;
import band.gosrock.domain.domains.ticket_item.domain.TicketItem;
import band.gosrock.domain.domains.user.domain.User;
import band.gosrock.infrastructure.config.mail.dto.EmailIssuedTicketInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.LongStream;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
Expand Down Expand Up @@ -78,11 +84,6 @@ public void addOptionAnswers(List<IssuedTicketOptionAnswer> answers) {
@Column(nullable = false)
private String uuid;

/*
발급 티켓 가격
*/
@Embedded private Money price;

/*
발급 티켓 상태
*/
Expand All @@ -100,15 +101,13 @@ public IssuedTicket(
String orderUuid,
Long orderLineId,
IssuedTicketItemInfoVo itemInfo,
Money price,
IssuedTicketStatus issuedTicketStatus,
List<IssuedTicketOptionAnswer> issuedTicketOptionAnswers) {
this.eventId = eventId;
this.userInfo = userInfo;
this.itemInfo = itemInfo;
this.orderUuid = orderUuid;
this.orderLineId = orderLineId;
this.price = price;
this.issuedTicketStatus = issuedTicketStatus;
this.issuedTicketOptionAnswers.addAll(issuedTicketOptionAnswers);
}
Expand Down Expand Up @@ -147,13 +146,47 @@ public IssuedTicketInfoVo toIssuedTicketInfoVo() {
return IssuedTicketInfoVo.from(this);
}

public static IssuedTicket create(
TicketItem ticketItem,
User user,
Order order,
Long eventId,
OrderLineItem orderLineItem) {
List<OrderOptionAnswer> orderOptionAnswers = orderLineItem.getOrderOptionAnswers();
return IssuedTicket.builder()
.issuedTicketOptionAnswers(
orderOptionAnswers.stream().map(IssuedTicketOptionAnswer::from).toList())
.itemInfo(IssuedTicketItemInfoVo.from(ticketItem))
.orderLineId(orderLineItem.getId())
.orderUuid(order.getUuid())
.issuedTicketStatus(IssuedTicketStatus.ENTRANCE_INCOMPLETE)
.userInfo(IssuedTicketUserInfoVo.from(user))
.eventId(eventId)
.build();
}

public static List<IssuedTicket> orderLineToIssuedTicket(
TicketItem ticketItem,
User user,
Order order,
Long eventId,
OrderLineItem orderLineItem) {
Long quantity = orderLineItem.getQuantity();
return LongStream.range(0, quantity)
.mapToObj(i -> IssuedTicket.create(ticketItem, user, order, eventId, orderLineItem))
.toList();
}

/*
발급 티켓을 이메일 형식 Dto로 매핑하는 메서드
*/
public EmailIssuedTicketInfo toEmailIssuedTicketInfo() {
return new EmailIssuedTicketInfo(
this.getIssuedTicketNo(),
this.getItemInfo().getTicketName(),
this.getCreatedAt(),
this.getIssuedTicketStatus().getKr(),
this.getPrice().toString());
this.getItemInfo().getPrice().toString());
}

/** ---------------------------- 상태 변환 관련 메서드 ---------------------------------- */
Expand Down
Loading

0 comments on commit e3c3ef5

Please sign in to comment.