Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : 티켓생성시 validation추가, 무료티켓에 유료 옵션 적용불가 #467

Merged
merged 6 commits into from
Feb 27, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -43,7 +44,7 @@ public class CreateTicketItemRequest {
@Schema(defaultValue = "0", nullable = false, example = "4000")
private Long price;

@NotNull
@Positive
@Schema(nullable = false, example = "100")
private Long supplyCount;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ public TicketItem(
this.supplyCount = supplyCount;
this.purchaseLimit = purchaseLimit;
this.type = type;
this.accountInfo = AccountInfoVo.valueOf(bankName, accountNumber, accountHolder);
this.accountInfo =
payType.equals(TicketPayType.DUDOONG_TICKET)
? AccountInfoVo.valueOf(bankName, accountNumber, accountHolder)
: null;
this.isQuantityPublic = isQuantityPublic;
this.isSellable = isSellable;
this.saleStartAt = saleStartAt;
Expand All @@ -117,6 +120,14 @@ public void addItemOptionGroup(OptionGroup optionGroup) {
throw ForbiddenOptionChangeException.EXCEPTION;
}

// 무료티켓에 유료 옵션 적용 불가
if (this.payType.equals(TicketPayType.FREE_TICKET)
&& optionGroup.getOptions().stream()
.anyMatch(
option -> option.getAdditionalPrice().isGreaterThan(Money.ZERO))) {
throw ForbiddenOptionPriceException.EXCEPTION;
}

// 중복 체크
if (this.hasItemOptionGroup(optionGroup.getId())) {
throw DuplicatedItemOptionGroupException.EXCEPTION;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package band.gosrock.domain.domains.ticket_item.exception;


import band.gosrock.common.exception.DuDoongCodeException;

public class ForbiddenOptionPriceException extends DuDoongCodeException {

public static final DuDoongCodeException EXCEPTION = new ForbiddenOptionPriceException();

private ForbiddenOptionPriceException() {
super(TicketItemErrorCode.FORBIDDEN_OPTION_PRICE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public enum TicketItemErrorCode implements BaseErrorCode {
@ExplainError("제휴되지 않은 호스트가 유료티켓 생성을 요청했을때 발생하는 오류입니다.")
INVALID_PARTNER(BAD_REQUEST, "Ticket_Item_400_3", "제휴된 호스트가 아닙니다."),
@ExplainError("해당 티켓상품에 적용되지 않은 옵션을 취소 시도할 경우 발생하는 오류입니다.")
NOT_APPLIED_ITEM_OPTION_GROUP(BAD_REQUEST, "Item_Option_Group_400_3", "적용되지 않은 옵션입니다.");
NOT_APPLIED_ITEM_OPTION_GROUP(BAD_REQUEST, "Item_Option_Group_400_3", "적용되지 않은 옵션입니다."),
@ExplainError("무료 티켓에 유료 옵션을 적용하려고 했을 때 발생하는 오류입니다.")
FORBIDDEN_OPTION_PRICE(BAD_REQUEST, "Item_Option_Group_400_4", "유료 옵션을 적용할 수 없습니다.");

private Integer status;
private String code;
Expand Down