Skip to content

Commit

Permalink
Api-v0.2.2
Browse files Browse the repository at this point in the history
Api-v0.2.2
  • Loading branch information
ImNM authored Feb 26, 2023
2 parents f326c63 + 70b4cbb commit 16eb888
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import band.gosrock.domain.domains.cart.domain.CartLineItem;
import band.gosrock.domain.domains.cart.domain.CartOptionAnswer;
import band.gosrock.domain.domains.cart.domain.CartValidator;
import band.gosrock.domain.domains.event.adaptor.EventAdaptor;
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.ticket_item.adaptor.OptionAdaptor;
import band.gosrock.domain.domains.ticket_item.adaptor.TicketItemAdaptor;
Expand All @@ -28,6 +29,7 @@ public class CartMapper {
private final TicketItemAdaptor ticketItemAdaptor;
private final OptionAdaptor optionAdaptor;
private final CartValidator cartValidator;
private final EventAdaptor eventAdaptor;

private final CartAdaptor cartAdaptor;

Expand All @@ -45,7 +47,7 @@ public CartResponse toCartResponse(Cart cart) {
private CartResponse getCartResponse(Cart cart) {
List<CartLineItem> newCartLineItems = cart.getCartLineItems();
TicketItem ticketItem = ticketItemAdaptor.queryTicketItem(cart.getItemId());
Event event = ticketItem.getEvent();
Event event = eventAdaptor.findById(ticketItem.getEventId());
List<CartItemResponse> cartItemResponses =
getCartItemResponses(newCartLineItems, ticketItem.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class OrderBriefElement {
private final String itemName;

@Schema(description = "아이템 총 갯수")
private final int totalQuantity;
private final Long totalQuantity;

public static OrderBriefElement of(Order order, Event event, IssuedTickets issuedTickets) {
return OrderBriefElement.builder()
Expand All @@ -48,7 +48,7 @@ public static OrderBriefElement of(Order order, Event event, IssuedTickets issue
.orderStatus(order.getOrderStatus())
.eventProfile(event.toEventProfileVo())
.itemName(order.getOrderName())
.totalQuantity(issuedTickets.getTotalQuantity())
.totalQuantity(order.getTotalQuantity())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TicketItemMapper {
private final TicketItemAdaptor ticketItemAdaptor;
private final EventAdaptor eventAdaptor;

public TicketItem toTicketItem(CreateTicketItemRequest createTicketItemRequest, Event event) {
public TicketItem toTicketItem(CreateTicketItemRequest createTicketItemRequest, Long eventId) {

return TicketItem.builder()
.payType(createTicketItemRequest.getPayType())
Expand All @@ -38,7 +38,7 @@ public TicketItem toTicketItem(CreateTicketItemRequest createTicketItemRequest,
.accountHolder(createTicketItemRequest.getAccountHolder())
.isQuantityPublic(createTicketItemRequest.getIsQuantityPublic())
.isSellable(true)
.event(event)
.eventId(eventId)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class TicketOptionMapper {
private final OptionGroupAdaptor optionGroupAdaptor;

public OptionGroup toOptionGroup(
CreateTicketOptionRequest createTicketOptionRequest, Event event) {
CreateTicketOptionRequest createTicketOptionRequest, Long eventId) {
return OptionGroup.builder()
.event(event)
.eventId(eventId)
.type(createTicketOptionRequest.getType())
.name(createTicketOptionRequest.getName())
.description(createTicketOptionRequest.getDescription())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public TicketItemResponse execute(
Boolean isPartner = host.getPartner();
TicketItem ticketItem =
ticketItemService.createTicketItem(
ticketItemMapper.toTicketItem(createTicketItemRequest, event), isPartner);
ticketItemMapper.toTicketItem(createTicketItemRequest, eventId), isPartner);

return TicketItemResponse.from(ticketItem, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import band.gosrock.common.annotation.UseCase;
import band.gosrock.domain.common.vo.Money;
import band.gosrock.domain.domains.event.adaptor.EventAdaptor;
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.ticket_item.domain.OptionGroup;
import band.gosrock.domain.domains.ticket_item.service.TicketOptionService;
import lombok.RequiredArgsConstructor;
Expand All @@ -27,11 +26,9 @@ public class CreateTicketOptionUseCase {
public OptionGroupResponse execute(
CreateTicketOptionRequest createTicketOptionRequest, Long eventId) {

Event event = eventAdaptor.findById(eventId);

OptionGroup ticketOption =
ticketOptionMapper
.toOptionGroup(createTicketOptionRequest, event)
.toOptionGroup(createTicketOptionRequest, eventId)
.createTicketOption(
Money.wons(createTicketOptionRequest.getAdditionalPrice()));
OptionGroup ticketOptionResult = ticketOptionService.createTicketOption(ticketOption);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import band.gosrock.common.annotation.Validator;
import band.gosrock.domain.domains.cart.exception.CartItemNotOneTypeException;
import band.gosrock.domain.domains.cart.exception.CartNotAnswerAllOptionGroupException;
import band.gosrock.domain.domains.event.adaptor.EventAdaptor;
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.issuedTicket.adaptor.IssuedTicketAdaptor;
import band.gosrock.domain.domains.ticket_item.adaptor.OptionAdaptor;
Expand All @@ -20,14 +21,15 @@ public class CartValidator {

private final TicketItemAdaptor itemAdaptor;
private final IssuedTicketAdaptor issuedTicketAdaptor;
private final EventAdaptor eventAdaptor;

private final OptionAdaptor optionAdaptor;

public void validCanCreate(Cart cart) {
validItemKindIsOneType(cart);
validCorrectAnswer(cart);
TicketItem item = getItem(cart);
Event event = item.getEvent();
Event event = eventAdaptor.findById(item.getEventId());
validAnswerToAllQuestion(cart, item);
validEventIsOpen(event);
validTicketingTime(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class OrderToIssuedTicketService {
public List<IssuedTicket> execute(TicketItem ticketItem, String orderUuid, Long userId) {
User user = userAdaptor.queryUser(userId);
Order order = orderAdaptor.findByOrderUuid(orderUuid);
Long eventId = ticketItem.getEvent().getId();
Long eventId = ticketItem.getEventId();
return order.getOrderLineItems().stream()
.map(
orderLineItem ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public OptionGroup queryOptionGroup(Long optionGroupId) {
}

public List<OptionGroup> findAllByEventId(Long eventId) {
return optionGroupRepository.findAllByEvent_IdAndOptionGroupStatus(
return optionGroupRepository.findAllByEventIdAndOptionGroupStatus(
eventId, OptionGroupStatus.VALID);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public TicketItem queryTicketItem(Long ticketItemId) {
}

public List<TicketItem> findAllByEventId(Long eventId) {
return ticketItemRepository.findAllByEvent_IdAndTicketItemStatus(
return ticketItemRepository.findAllByEventIdAndTicketItemStatus(
eventId, TicketItemStatus.VALID);
}

public Boolean existsByEventId(Long eventId) {
return ticketItemRepository.existsByEvent_Id(eventId);
return ticketItemRepository.existsByEventId(eventId);
}

public TicketItem save(TicketItem ticketItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static band.gosrock.domain.domains.ticket_item.domain.OptionGroupType.*;

import band.gosrock.domain.common.vo.Money;
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.ticket_item.exception.ForbiddenOptionGroupDeleteException;
import band.gosrock.domain.domains.ticket_item.exception.InvalidOptionGroupException;
import java.util.ArrayList;
Expand All @@ -28,9 +27,7 @@ public class OptionGroup {
@Column(name = "option_group_id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "event_id", nullable = false)
private Event event;
private Long eventId;

// 옵션 그룹 응답 형식
@Enumerated(EnumType.STRING)
Expand All @@ -55,13 +52,13 @@ public class OptionGroup {

@Builder
public OptionGroup(
Event event,
Long eventId,
OptionGroupType type,
String name,
String description,
Boolean isEssential,
List<Option> options) {
this.event = event;
this.eventId = eventId;
this.type = type;
this.name = name;
this.description = description;
Expand All @@ -72,7 +69,7 @@ public OptionGroup(
}

public void validateEventId(Long eventId) {
if (!this.getEvent().getId().equals(eventId)) {
if (!this.getEventId().equals(eventId)) {
throw InvalidOptionGroupException.EXCEPTION;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import band.gosrock.domain.common.model.BaseTimeEntity;
import band.gosrock.domain.common.vo.AccountInfoVo;
import band.gosrock.domain.common.vo.Money;
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.ticket_item.exception.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
Expand Down Expand Up @@ -73,9 +72,7 @@ public class TicketItem extends BaseTimeEntity {
@ColumnDefault(value = "'VALID'")
private TicketItemStatus ticketItemStatus = TicketItemStatus.VALID;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "event_id", nullable = false)
private Event event;
private Long eventId;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
private final List<ItemOptionGroup> itemOptionGroups = new ArrayList<>();
Expand All @@ -97,7 +94,7 @@ public TicketItem(
Boolean isSellable,
LocalDateTime saleStartAt,
LocalDateTime saleEndAt,
Event event) {
Long eventId) {
this.payType = payType;
this.name = name;
this.description = description;
Expand All @@ -111,7 +108,7 @@ public TicketItem(
this.isSellable = isSellable;
this.saleStartAt = saleStartAt;
this.saleEndAt = saleEndAt;
this.event = event;
this.eventId = eventId;
}

public void addItemOptionGroup(OptionGroup optionGroup) {
Expand Down Expand Up @@ -161,7 +158,7 @@ public void softDeleteTicketItem() {
}

public void validateEventId(Long eventId) {
if (!this.getEvent().getId().equals(eventId)) {
if (!this.getEventId().equals(eventId)) {
throw InvalidTicketItemException.EXCEPTION;
}
}
Expand Down Expand Up @@ -254,6 +251,6 @@ public Boolean isSold() {
}

public Long getEventId() {
return event.getId();
return eventId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface OptionGroupRepository extends JpaRepository<OptionGroup, Long>
Optional<OptionGroup> findByIdAndOptionGroupStatus(
Long optionGroupId, OptionGroupStatus status);

List<OptionGroup> findAllByEvent_IdAndOptionGroupStatus(Long eventId, OptionGroupStatus status);
List<OptionGroup> findAllByEventIdAndOptionGroupStatus(Long eventId, OptionGroupStatus status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

public interface TicketItemRepository extends JpaRepository<TicketItem, Long> {

List<TicketItem> findAllByEvent_IdAndTicketItemStatus(Long eventId, TicketItemStatus status);
List<TicketItem> findAllByEventIdAndTicketItemStatus(Long eventId, TicketItemStatus status);

Boolean existsByEvent_Id(Long eventId);
Boolean existsByEventId(Long eventId);

Optional<TicketItem> findByIdAndTicketItemStatus(Long ticketItemId, TicketItemStatus status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public EmailUserInfo toEmailUserInfo() {
}

public AlimTalkUserInfo toAlimTalkUserInfo() throws NumberParseException {
if (profile.getPhoneNumberVo().getPhoneNumber() == null
|| profile.getPhoneNumberVo().getPhoneNumber().isEmpty()) {
if (profile.getPhoneNumberVo() == null) {
throw EmptyPhoneNumException.EXCEPTION;
}
return new AlimTalkUserInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import band.gosrock.domain.domains.cart.exception.CartItemNotOneTypeException;
import band.gosrock.domain.domains.cart.exception.CartNotAnswerAllOptionGroupException;
import band.gosrock.domain.domains.event.adaptor.EventAdaptor;
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.event.exception.EventNotOpenException;
import band.gosrock.domain.domains.event.exception.EventTicketingTimeIsPassedException;
Expand Down Expand Up @@ -43,12 +44,15 @@ class CartValidatorTest {
@Mock TicketItem item;

@Mock IssuedTicketAdaptor issuedTicketAdaptor;
@Mock EventAdaptor eventAdaptor;

CartValidator cartValidator;

@BeforeEach
void setUp() {
cartValidator = new CartValidator(ticketItemAdaptor, issuedTicketAdaptor, optionAdaptor);
cartValidator =
new CartValidator(
ticketItemAdaptor, issuedTicketAdaptor, eventAdaptor, optionAdaptor);
}

@Test
Expand Down

0 comments on commit 16eb888

Please sign in to comment.