Skip to content

Commit

Permalink
Merge pull request #32 from KUSITMS-Team-A/fix/31-event-manage
Browse files Browse the repository at this point in the history
[Fix] 이벤트 API 오류 수정
  • Loading branch information
yeop0740 authored Nov 22, 2023
2 parents 59c4b74 + d922006 commit 9c84543
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/main/java/com/backend/domain/event/dto/CreateEventRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> conditions;
Expand All @@ -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;
Expand All @@ -65,4 +89,11 @@ private List<Condition> createConditions() {
.toList();
}

private LocalDate createEndDate() {
if (duration == null) {
return startDate;
}
return startDate.plusDays(duration.getPlusDate());
}

}

0 comments on commit 9c84543

Please sign in to comment.