diff --git a/src/main/java/com/backend/domain/event/dto/CreateEventRequest.java b/src/main/java/com/backend/domain/event/dto/CreateEventRequest.java index 1cfa3c3..99be442 100644 --- a/src/main/java/com/backend/domain/event/dto/CreateEventRequest.java +++ b/src/main/java/com/backend/domain/event/dto/CreateEventRequest.java @@ -5,6 +5,7 @@ import com.backend.domain.event.entity.Event; import com.backend.domain.popup.domain.EndDateType; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -18,12 +19,15 @@ public class CreateEventRequest { @Schema(example = "3") + @NotEmpty private Long storeId; @Schema(example = "COUPON") + @NotEmpty private BenefitType type; @Schema(example = "5000원 할인 쿠폰") + @NotEmpty private String name; private List conditions; @@ -39,19 +43,39 @@ public class CreateEventRequest { @Schema(example = "일주일간") private EndDateType duration; + { + startDate = LocalDate.now(); + } + public Event toEntity() { + validateDuration(); + validateQuantity(); Event event = Event.builder() .type(type) .name(name) - .quantity(createDiscount()) - .discount(discount) + .quantity(quantity) + .discount(createDiscount()) .startDate(startDate) - .endDate(startDate.plusDays(duration.getPlusDate())) + .endDate(createEndDate()) .build(); event.addAll(createConditions()); return event; } + private void validateDuration() { + if (type.equals(BenefitType.STAMP)) { + if (duration == null) { + throw new RuntimeException(); + } + } + } + + public void validateQuantity() { + if (quantity <= 0 && quantity != -1) { + throw new RuntimeException(); + } + } + private int createDiscount() { if (type.equals(BenefitType.STAMP)) { return 0; @@ -65,4 +89,11 @@ private List createConditions() { .toList(); } + private LocalDate createEndDate() { + if (duration == null) { + return startDate; + } + return startDate.plusDays(duration.getPlusDate()); + } + }