-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from KUSITMS-Team-A/feature/29-event-manage
[#29] 이벤트 관리 API 구현
- Loading branch information
Showing
17 changed files
with
658 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
src/main/java/com/backend/domain/contract/entity/Event.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/com/backend/domain/event/controller/EventController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.backend.domain.event.controller; | ||
|
||
import com.backend.common.dto.ResponseDto; | ||
import com.backend.domain.auth.dto.Login; | ||
import com.backend.domain.auth.dto.LoginUser; | ||
import com.backend.domain.event.dto.*; | ||
import com.backend.domain.event.service.EventService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/event") | ||
@SecurityRequirement(name = "bearer-key") | ||
@Tag(name = "이벤트", description = "이벤트 관리 API") | ||
public class EventController { | ||
|
||
private final EventService eventService; | ||
|
||
@PostMapping | ||
@Operation( | ||
summary = "이벤트 등록", | ||
description = | ||
"<p>쿠폰과 스탬프를 등록합니다</p>" + | ||
"<p>쿠폰을 등록할 때에는 type을 COUPON으로 선택하고 startDate와 duration을 입력하지 않는다.</p>" + | ||
"<p>스탬프를 등록할 때에는 type을 STAMP 선택하고 startDate와 duration을 입력한다. discount는 입력하지 않는다.</p>") | ||
public ResponseEntity<Void> createEvent(@Parameter(hidden = true) @Login LoginUser loginUser, @RequestBody CreateEventRequest request) { | ||
eventService.createEvent(loginUser, request); | ||
return ResponseDto.created(); | ||
} | ||
|
||
@GetMapping("/coupon") | ||
@Operation(summary = "쿠폰 목록 조회") | ||
public ResponseEntity<ReadCouponsDto> readCoupons(@Parameter(hidden = true) @Login LoginUser loginUser, @ModelAttribute ReadEventsRequest request) { | ||
ReadCouponsDto events = eventService.readCoupons(loginUser, request); | ||
return ResponseDto.ok(events); | ||
} | ||
|
||
@GetMapping | ||
@Operation(summary = "이벤트 목록 조회") | ||
public ResponseEntity<ReadEventsDto> readEvents(@Parameter(hidden = true) @Login LoginUser loginUser, @ModelAttribute ReadEventsRequest request) { | ||
ReadEventsDto events = eventService.readEvents(loginUser, request); | ||
return ResponseDto.ok(events); | ||
} | ||
|
||
@PatchMapping | ||
@Operation(summary = "이벤트 수정") | ||
public ResponseEntity<Void> updateEvent(@Parameter(hidden = true) @Login LoginUser loginUser, @RequestBody UpdateEventRequest request) { | ||
eventService.updateEvent(loginUser, request); | ||
return ResponseDto.ok(); | ||
} | ||
|
||
|
||
@DeleteMapping("/{eventId}") | ||
@Operation(summary = "이벤트 삭제") | ||
public ResponseEntity<Void> deleteEvent(@Parameter(hidden = true) @Login LoginUser loginUser, @Parameter(name = "eventId") @PathVariable Long eventId) { | ||
eventService.deleteEvent(loginUser, eventId); | ||
return ResponseDto.ok(); | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/com/backend/domain/event/dto/CreateEventRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.backend.domain.event.dto; | ||
|
||
import com.backend.domain.benefit.entity.BenefitType; | ||
import com.backend.domain.event.entity.Condition; | ||
import com.backend.domain.event.entity.Event; | ||
import com.backend.domain.popup.domain.EndDateType; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CreateEventRequest { | ||
|
||
@Schema(example = "3") | ||
private Long storeId; | ||
|
||
@Schema(example = "COUPON") | ||
private BenefitType type; | ||
|
||
@Schema(example = "5000원 할인 쿠폰") | ||
private String name; | ||
|
||
private List<String> conditions; | ||
|
||
private int discount; | ||
|
||
@Schema(example = "50") | ||
private int quantity; | ||
|
||
@Schema(example = "2023-11-22") | ||
private LocalDate startDate; | ||
|
||
@Schema(example = "일주일간") | ||
private EndDateType duration; | ||
|
||
public Event toEntity() { | ||
Event event = Event.builder() | ||
.type(type) | ||
.name(name) | ||
.quantity(createDiscount()) | ||
.discount(discount) | ||
.startDate(startDate) | ||
.endDate(startDate.plusDays(duration.getPlusDate())) | ||
.build(); | ||
event.addAll(createConditions()); | ||
return event; | ||
} | ||
|
||
private int createDiscount() { | ||
if (type.equals(BenefitType.STAMP)) { | ||
return 0; | ||
} | ||
return discount; | ||
} | ||
|
||
private List<Condition> createConditions() { | ||
return conditions.stream() | ||
.map(Condition::new) | ||
.toList(); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/backend/domain/event/dto/ReadCouponDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.backend.domain.event.dto; | ||
|
||
import com.backend.domain.event.entity.Condition; | ||
import com.backend.domain.event.entity.Event; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ReadCouponDto { | ||
|
||
private Long couponStoreId; | ||
|
||
private String couponStore; | ||
|
||
private Long couponId; | ||
|
||
private String couponName; | ||
|
||
private List<String> couponCondition; | ||
|
||
private int couponQuantity; | ||
|
||
public static ReadCouponDto from(Event coupon) { | ||
return ReadCouponDto.builder() | ||
.couponStoreId(coupon.getContract().getStore().getStoreId()) | ||
.couponStore(coupon.getContract().getStore().getName()) | ||
.couponId(coupon.getEventId()) | ||
.couponName(coupon.getName()) | ||
.couponQuantity(coupon.getQuantity()) | ||
.couponCondition(getConditionStrings(coupon)) | ||
.build(); | ||
} | ||
|
||
private static List<String> getConditionStrings(Event coupon) { | ||
return coupon.getConditions().stream() | ||
.map(Condition::getContent) | ||
.toList(); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/backend/domain/event/dto/ReadCouponsDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.backend.domain.event.dto; | ||
|
||
import com.backend.domain.event.entity.Event; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ReadCouponsDto { | ||
|
||
private List<ReadCouponDto> coupons; | ||
|
||
private int pageNumber; | ||
|
||
private Long totalCount; | ||
|
||
private int totalPages; | ||
|
||
public static ReadCouponsDto from(Page<Event> coupons) { | ||
return ReadCouponsDto.builder() | ||
.pageNumber(coupons.getNumber()) | ||
.totalCount(coupons.getTotalElements()) | ||
.totalPages(coupons.getTotalPages()) | ||
.coupons(getReadCouponDtos(coupons)) | ||
.build(); | ||
} | ||
|
||
private static List<ReadCouponDto> getReadCouponDtos(Page<Event> coupons) { | ||
return coupons.getContent().stream() | ||
.map(ReadCouponDto::from) | ||
.toList(); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/backend/domain/event/dto/ReadEventDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.backend.domain.event.dto; | ||
|
||
import com.backend.domain.benefit.entity.BenefitType; | ||
import com.backend.domain.event.entity.Condition; | ||
import com.backend.domain.event.entity.Event; | ||
import com.backend.domain.store.dto.StoreDto; | ||
import com.backend.domain.store.entity.Store; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ReadEventDto { | ||
|
||
private StoreDto store; | ||
|
||
private Long eventId; | ||
|
||
private BenefitType eventType; | ||
|
||
private String eventName; | ||
|
||
private List<String> eventCondition; | ||
|
||
private int eventQuantity; | ||
|
||
public static ReadEventDto from(Event event, Store store) { | ||
return ReadEventDto.builder() | ||
.eventId(event.getEventId()) | ||
.eventType(event.getType()) | ||
.eventName(event.getName()) | ||
.eventQuantity(event.getQuantity()) | ||
.store(StoreDto.from(store)) | ||
.eventCondition(getConditionStrings(event)) | ||
.build(); | ||
} | ||
|
||
private static List<String> getConditionStrings(Event event) { | ||
return event.getConditions().stream() | ||
.map(Condition::getContent) | ||
.toList(); | ||
} | ||
|
||
} |
Oops, something went wrong.