From 2dbb3a455412abb38d606b58acf1d49c0108bfd6 Mon Sep 17 00:00:00 2001 From: DongHoon Lee <125895298+hoonyworld@users.noreply.github.com> Date: Wed, 2 Oct 2024 21:12:18 +0900 Subject: [PATCH] =?UTF-8?q?[refactor]=20#221=20-=20=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=EC=97=90=EC=84=9C=20=EC=BA=90?= =?UTF-8?q?=EB=9F=AC=EC=85=80=20=EC=9D=91=EB=8B=B5=20=EC=8B=9C=20=EC=BA=90?= =?UTF-8?q?=EB=9F=AC=EC=85=80=20=EB=B2=88=ED=98=B8=EB=A1=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=ED=95=B4=EC=84=9C=20=EC=A3=BC=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EB=A9=94=EC=9D=B8=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B5=9C=EC=A0=81=ED=99=94=20(#222)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [#221] rename: DTO 이름 변경 및 import문 최신화 * [#221] chore(AdminApi): 통일성을 위해 mapping 어노테이션 삭제 * [#221] rename(HomeFindRequest): 요청 DTO 네이밍 구체화 * [#221] rename(HomeFindAllResponse): 응답 DTO 네이밍 구체화 * [#221] refactor(PerformanceService): getHomePerformanceList, getPromotions 메서드 이동 및 코드 포맷팅 적용 * [#221] feat(HomeService): 공연 및 홍보 조회 서비스 로직 최적화 * [#221] feat(ScheduleService): 공연의 회차 중 가장 dueDate가 적은 회차의 dueDate를 반환하는 메서드 구현 * [#221] refactor(HomePromotionDetail): 정적 팩토리 메서드 내에서 초기화해서 return 하도록 변경 * [#221] refactor(HomePerformanceDetail): 정적 팩토리 메서드 내에서 초기화해서 return 하도록 변경 * [#221] feat(HomeApi): Home API 스웨거 명세서 작성 * [#221] refactor(HomeController): 로직 최적화 * [#221] fix(HomeService): 음수는 내림차순, 양수는 오름차순으로 정렬하도록 수정 --- .../beat/admin/adapter/in/api/AdminApi.java | 10 +- .../admin/adapter/in/api/AdminController.java | 10 +- .../beat/admin/application/AdminService.java | 4 +- ...equest.java => CarouselHandleRequest.java} | 2 +- .../dto/request/PromotionHandleRequest.java | 2 +- ...se.java => CarouselHandleAllResponse.java} | 6 +- .../com/beat/admin/facade/AdminFacade.java | 22 +- .../com/beat/admin/port/in/AdminUseCase.java | 4 +- .../beat/domain/performance/api/HomeApi.java | 33 +++ .../performance/api/HomeController.java | 39 +-- .../performance/application/HomeService.java | 71 +++++ .../application/PerformanceService.java | 279 ++++-------------- .../dto/home/HomeFindAllResponse.java | 12 + ...{HomeRequest.java => HomeFindRequest.java} | 4 +- .../dto/home/HomePerformanceDetail.java | 36 ++- .../dto/home/HomePromotionDetail.java | 26 +- .../application/dto/home/HomeResponse.java | 12 - .../application/PromotionService.java | 2 +- .../promotion/port/in/PromotionUseCase.java | 2 +- .../schedule/application/ScheduleService.java | 16 +- 20 files changed, 282 insertions(+), 310 deletions(-) rename src/main/java/com/beat/admin/application/dto/request/{CarouselProcessRequest.java => CarouselHandleRequest.java} (94%) rename src/main/java/com/beat/admin/application/dto/response/{CarouselProcessAllResponse.java => CarouselHandleAllResponse.java} (80%) create mode 100644 src/main/java/com/beat/domain/performance/api/HomeApi.java create mode 100644 src/main/java/com/beat/domain/performance/application/HomeService.java create mode 100644 src/main/java/com/beat/domain/performance/application/dto/home/HomeFindAllResponse.java rename src/main/java/com/beat/domain/performance/application/dto/home/{HomeRequest.java => HomeFindRequest.java} (70%) delete mode 100644 src/main/java/com/beat/domain/performance/application/dto/home/HomeResponse.java diff --git a/src/main/java/com/beat/admin/adapter/in/api/AdminApi.java b/src/main/java/com/beat/admin/adapter/in/api/AdminApi.java index 5523480b..f5fb2ea6 100644 --- a/src/main/java/com/beat/admin/adapter/in/api/AdminApi.java +++ b/src/main/java/com/beat/admin/adapter/in/api/AdminApi.java @@ -2,8 +2,8 @@ import com.beat.admin.application.dto.response.CarouselFindAllResponse; import com.beat.admin.application.dto.response.UserFindAllResponse; -import com.beat.admin.application.dto.request.CarouselProcessRequest; -import com.beat.admin.application.dto.response.CarouselProcessAllResponse; +import com.beat.admin.application.dto.request.CarouselHandleRequest; +import com.beat.admin.application.dto.response.CarouselHandleAllResponse; import com.beat.global.auth.annotation.CurrentMember; import com.beat.global.common.dto.ErrorResponse; import com.beat.global.common.dto.SuccessResponse; @@ -16,7 +16,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; @@ -128,9 +127,8 @@ ResponseEntity> readAllCarouselImages( ) } ) - @PutMapping("/carousels") - ResponseEntity> processCarouselImages( + ResponseEntity> processCarouselImages( @CurrentMember Long memberId, - @RequestBody CarouselProcessRequest request + @RequestBody CarouselHandleRequest request ); } diff --git a/src/main/java/com/beat/admin/adapter/in/api/AdminController.java b/src/main/java/com/beat/admin/adapter/in/api/AdminController.java index bd716bd5..20dd1f31 100644 --- a/src/main/java/com/beat/admin/adapter/in/api/AdminController.java +++ b/src/main/java/com/beat/admin/adapter/in/api/AdminController.java @@ -1,8 +1,8 @@ package com.beat.admin.adapter.in.api; import com.beat.admin.application.dto.response.CarouselFindAllResponse; -import com.beat.admin.application.dto.request.CarouselProcessRequest; -import com.beat.admin.application.dto.response.CarouselProcessAllResponse; +import com.beat.admin.application.dto.request.CarouselHandleRequest; +import com.beat.admin.application.dto.response.CarouselHandleAllResponse; import com.beat.admin.exception.AdminSuccessCode; import com.beat.admin.application.dto.response.UserFindAllResponse; import com.beat.admin.facade.AdminFacade; @@ -69,10 +69,10 @@ public ResponseEntity> readAllCarouselI @Override @PutMapping("/carousels") - public ResponseEntity> processCarouselImages( + public ResponseEntity> processCarouselImages( @CurrentMember Long memberId, - @RequestBody CarouselProcessRequest request) { - CarouselProcessAllResponse response = adminFacade.checkMemberAndProcessAllPromotionsSortedByCarouselNumber(memberId, request); + @RequestBody CarouselHandleRequest request) { + CarouselHandleAllResponse response = adminFacade.checkMemberAndProcessAllPromotionsSortedByCarouselNumber(memberId, request); return ResponseEntity.status(HttpStatus.OK) .body(SuccessResponse.of(AdminSuccessCode.UPDATE_ALL_CAROUSEL_PROMOTIONS_SUCCESS, response)); } diff --git a/src/main/java/com/beat/admin/application/AdminService.java b/src/main/java/com/beat/admin/application/AdminService.java index 3ded8d8d..8b8eb376 100644 --- a/src/main/java/com/beat/admin/application/AdminService.java +++ b/src/main/java/com/beat/admin/application/AdminService.java @@ -1,7 +1,7 @@ package com.beat.admin.application; -import com.beat.admin.application.dto.request.CarouselProcessRequest.PromotionGenerateRequest; -import com.beat.admin.application.dto.request.CarouselProcessRequest.PromotionModifyRequest; +import com.beat.admin.application.dto.request.CarouselHandleRequest.PromotionGenerateRequest; +import com.beat.admin.application.dto.request.CarouselHandleRequest.PromotionModifyRequest; import com.beat.admin.port.in.AdminUseCase; import com.beat.domain.performance.domain.Performance; import com.beat.domain.performance.port.in.PerformanceUseCase; diff --git a/src/main/java/com/beat/admin/application/dto/request/CarouselProcessRequest.java b/src/main/java/com/beat/admin/application/dto/request/CarouselHandleRequest.java similarity index 94% rename from src/main/java/com/beat/admin/application/dto/request/CarouselProcessRequest.java rename to src/main/java/com/beat/admin/application/dto/request/CarouselHandleRequest.java index bb094771..c5aa18a7 100644 --- a/src/main/java/com/beat/admin/application/dto/request/CarouselProcessRequest.java +++ b/src/main/java/com/beat/admin/application/dto/request/CarouselHandleRequest.java @@ -4,7 +4,7 @@ import com.beat.domain.promotion.domain.CarouselNumber; -public record CarouselProcessRequest( +public record CarouselHandleRequest( List carousels ) { diff --git a/src/main/java/com/beat/admin/application/dto/request/PromotionHandleRequest.java b/src/main/java/com/beat/admin/application/dto/request/PromotionHandleRequest.java index c7c7307b..e293d603 100644 --- a/src/main/java/com/beat/admin/application/dto/request/PromotionHandleRequest.java +++ b/src/main/java/com/beat/admin/application/dto/request/PromotionHandleRequest.java @@ -1,6 +1,6 @@ package com.beat.admin.application.dto.request; -import static com.beat.admin.application.dto.request.CarouselProcessRequest.*; +import static com.beat.admin.application.dto.request.CarouselHandleRequest.*; import com.beat.domain.promotion.domain.CarouselNumber; import com.fasterxml.jackson.annotation.JsonSubTypes; diff --git a/src/main/java/com/beat/admin/application/dto/response/CarouselProcessAllResponse.java b/src/main/java/com/beat/admin/application/dto/response/CarouselHandleAllResponse.java similarity index 80% rename from src/main/java/com/beat/admin/application/dto/response/CarouselProcessAllResponse.java rename to src/main/java/com/beat/admin/application/dto/response/CarouselHandleAllResponse.java index 35b26b98..999224b0 100644 --- a/src/main/java/com/beat/admin/application/dto/response/CarouselProcessAllResponse.java +++ b/src/main/java/com/beat/admin/application/dto/response/CarouselHandleAllResponse.java @@ -5,15 +5,15 @@ import com.beat.domain.promotion.domain.Promotion; -public record CarouselProcessAllResponse( +public record CarouselHandleAllResponse( List modifiedPromotions ) { - public static CarouselProcessAllResponse from(List promotions) { + public static CarouselHandleAllResponse from(List promotions) { List modifiedPromotions = promotions.stream() .map(PromotionResponse::from) .collect(Collectors.toList()); - return new CarouselProcessAllResponse(modifiedPromotions); + return new CarouselHandleAllResponse(modifiedPromotions); } public record PromotionResponse( diff --git a/src/main/java/com/beat/admin/facade/AdminFacade.java b/src/main/java/com/beat/admin/facade/AdminFacade.java index f2d67cc4..f4c7902e 100644 --- a/src/main/java/com/beat/admin/facade/AdminFacade.java +++ b/src/main/java/com/beat/admin/facade/AdminFacade.java @@ -3,10 +3,10 @@ import com.beat.admin.application.dto.request.PromotionHandleRequest; import com.beat.admin.application.dto.response.CarouselFindAllResponse; import com.beat.admin.application.dto.response.UserFindAllResponse; -import com.beat.admin.application.dto.request.CarouselProcessRequest; -import com.beat.admin.application.dto.request.CarouselProcessRequest.PromotionGenerateRequest; -import com.beat.admin.application.dto.request.CarouselProcessRequest.PromotionModifyRequest; -import com.beat.admin.application.dto.response.CarouselProcessAllResponse; +import com.beat.admin.application.dto.request.CarouselHandleRequest; +import com.beat.admin.application.dto.request.CarouselHandleRequest.PromotionGenerateRequest; +import com.beat.admin.application.dto.request.CarouselHandleRequest.PromotionModifyRequest; +import com.beat.admin.application.dto.response.CarouselHandleAllResponse; import com.beat.admin.port.in.AdminUseCase; import com.beat.domain.member.port.in.MemberUseCase; import com.beat.domain.promotion.domain.CarouselNumber; @@ -64,8 +64,8 @@ public CarouselFindAllResponse checkMemberAndFindAllPromotionsSortedByCarouselNu return CarouselFindAllResponse.from(promotions); } - public CarouselProcessAllResponse checkMemberAndProcessAllPromotionsSortedByCarouselNumber(Long memberId, - CarouselProcessRequest request) { + public CarouselHandleAllResponse checkMemberAndProcessAllPromotionsSortedByCarouselNumber(Long memberId, + CarouselHandleRequest request) { memberUseCase.findMemberById(memberId); @@ -85,10 +85,10 @@ public CarouselProcessAllResponse checkMemberAndProcessAllPromotionsSortedByCaro List sortedPromotions = adminUsecase.processPromotionsAndSortByCarouselNumber(modifyRequests, generateRequests, deleteCarouselNumbers, overlappingCarouselNumbers); - return CarouselProcessAllResponse.from(sortedPromotions); + return CarouselHandleAllResponse.from(sortedPromotions); } - private void categorizePromotionRequests(CarouselProcessRequest request, + private void categorizePromotionRequests(CarouselHandleRequest request, List modifyRequests, List generateRequests, Set requestCarouselNumbers) { @@ -111,15 +111,15 @@ private List findDeleteCarouselNumbers(Set reque } private List findOverlappingCarouselNumbers(Set requestCarouselNumbers, - List allExistingCarouselNumbers, CarouselProcessRequest request) { + List allExistingCarouselNumbers, CarouselHandleRequest request) { return allExistingCarouselNumbers.stream() .filter(requestCarouselNumbers::contains) .filter(existingCarouselNumber -> { Promotion existingPromotion = promotionUseCase.findPromotionByCarouselNumber(existingCarouselNumber); return request.carousels() .stream() - .filter(req -> req instanceof CarouselProcessRequest.PromotionModifyRequest) - .map(req -> (CarouselProcessRequest.PromotionModifyRequest)req) + .filter(req -> req instanceof CarouselHandleRequest.PromotionModifyRequest) + .map(req -> (CarouselHandleRequest.PromotionModifyRequest)req) .noneMatch(req -> req.promotionId() != null && req.promotionId().equals(existingPromotion.getId())); }) .toList(); diff --git a/src/main/java/com/beat/admin/port/in/AdminUseCase.java b/src/main/java/com/beat/admin/port/in/AdminUseCase.java index 747b812f..1f9d70dc 100644 --- a/src/main/java/com/beat/admin/port/in/AdminUseCase.java +++ b/src/main/java/com/beat/admin/port/in/AdminUseCase.java @@ -1,7 +1,7 @@ package com.beat.admin.port.in; -import com.beat.admin.application.dto.request.CarouselProcessRequest.PromotionGenerateRequest; -import com.beat.admin.application.dto.request.CarouselProcessRequest.PromotionModifyRequest; +import com.beat.admin.application.dto.request.CarouselHandleRequest.PromotionGenerateRequest; +import com.beat.admin.application.dto.request.CarouselHandleRequest.PromotionModifyRequest; import com.beat.domain.promotion.domain.CarouselNumber; import com.beat.domain.promotion.domain.Promotion; diff --git a/src/main/java/com/beat/domain/performance/api/HomeApi.java b/src/main/java/com/beat/domain/performance/api/HomeApi.java new file mode 100644 index 00000000..0b6e9e58 --- /dev/null +++ b/src/main/java/com/beat/domain/performance/api/HomeApi.java @@ -0,0 +1,33 @@ +package com.beat.domain.performance.api; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestParam; + +import com.beat.domain.performance.application.dto.home.HomeFindAllResponse; +import com.beat.domain.performance.domain.Genre; +import com.beat.global.common.dto.ErrorResponse; +import com.beat.global.common.dto.SuccessResponse; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; + +@Tag(name = "Home", description = "홈 화면에서 공연 및 홍보목록 조회 API") +public interface HomeApi { + + @Operation(summary = "전체 공연 및 홍보 목록 조회", description = "홈 화면에서 전체 공연 목록 및 홍보 목록을 조회하는 GET API") + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "홈 화면 공연 목록 조회가 성공적으로 완료되었습니다.", + content = @Content(schema = @Schema(implementation = SuccessResponse.class)) + ) + } + ) + ResponseEntity> getHomePerformanceList( + @RequestParam(required = false) Genre genre); +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/api/HomeController.java b/src/main/java/com/beat/domain/performance/api/HomeController.java index 7a7a7159..8ebd44b2 100644 --- a/src/main/java/com/beat/domain/performance/api/HomeController.java +++ b/src/main/java/com/beat/domain/performance/api/HomeController.java @@ -1,13 +1,14 @@ package com.beat.domain.performance.api; -import com.beat.domain.performance.application.PerformanceService; -import com.beat.domain.performance.application.dto.home.HomeRequest; -import com.beat.domain.performance.application.dto.home.HomeResponse; +import com.beat.domain.performance.application.HomeService; +import com.beat.domain.performance.application.dto.home.HomeFindRequest; +import com.beat.domain.performance.application.dto.home.HomeFindAllResponse; import com.beat.domain.performance.domain.Genre; import com.beat.domain.performance.exception.PerformanceSuccessCode; import com.beat.global.common.dto.SuccessResponse; -import io.swagger.v3.oas.annotations.Operation; + import lombok.RequiredArgsConstructor; + import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -17,19 +18,19 @@ @RestController @RequestMapping("/api/main") @RequiredArgsConstructor -public class HomeController { - - private final PerformanceService performanceService; - - @Operation(summary = "전체공연목록, 홍보목록 조회 API", description = "홈화면에서 전체공연목록, 홍보목록을 조회하는 GET API입니다.") - @GetMapping - public ResponseEntity> getHomePerformanceList(@RequestParam(required = false) String genre) { - HomeRequest homeRequest; - if (genre != null) { - homeRequest = new HomeRequest(Genre.valueOf(genre)); - } else { - homeRequest = new HomeRequest(null); - } HomeResponse homeResponse = performanceService.getHomePerformanceList(homeRequest); - return ResponseEntity.ok(SuccessResponse.of(PerformanceSuccessCode.HOME_PERFORMANCE_RETRIEVE_SUCCESS, homeResponse)); - } +public class HomeController implements HomeApi { + + private final HomeService homeService; + + @Override + @GetMapping + public ResponseEntity> getHomePerformanceList( + @RequestParam(required = false) Genre genre) { + + HomeFindRequest request = new HomeFindRequest(genre); + + HomeFindAllResponse response = homeService.findHomePerformanceList(request); + return ResponseEntity.ok( + SuccessResponse.of(PerformanceSuccessCode.HOME_PERFORMANCE_RETRIEVE_SUCCESS, response)); + } } \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/HomeService.java b/src/main/java/com/beat/domain/performance/application/HomeService.java new file mode 100644 index 00000000..6ac6887c --- /dev/null +++ b/src/main/java/com/beat/domain/performance/application/HomeService.java @@ -0,0 +1,71 @@ +package com.beat.domain.performance.application; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.beat.domain.performance.application.dto.home.HomeFindAllResponse; +import com.beat.domain.performance.application.dto.home.HomeFindRequest; +import com.beat.domain.performance.application.dto.home.HomePerformanceDetail; +import com.beat.domain.performance.application.dto.home.HomePromotionDetail; +import com.beat.domain.performance.dao.PerformanceRepository; +import com.beat.domain.performance.domain.Genre; +import com.beat.domain.performance.domain.Performance; +import com.beat.domain.promotion.domain.Promotion; +import com.beat.domain.promotion.port.in.PromotionUseCase; +import com.beat.domain.schedule.application.ScheduleService; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class HomeService { + + private final ScheduleService scheduleService; + private final PromotionUseCase promotionUseCase; + + private final PerformanceRepository performanceRepository; + + @Transactional(readOnly = true) + public HomeFindAllResponse findHomePerformanceList(HomeFindRequest homeFindRequest) { + + List performances = findPerformancesByGenre(homeFindRequest); + List promotions = findAllPromotionsSortedByCarouselNumber(); + + if (performances.isEmpty()) { + return HomeFindAllResponse.of(promotions, new ArrayList<>()); + } + + List sortedPerformances = performances.stream() + .map(performance -> { + int minDueDate = scheduleService.getMinDueDateForPerformance(performance.getId()); + return HomePerformanceDetail.of(performance, minDueDate); + }) + .sorted(Comparator.comparingInt(detail -> detail.dueDate() < 0 ? 1 : 0) + .thenComparingInt(detail -> Math.abs(detail.dueDate()))) + .toList(); + + return HomeFindAllResponse.of(promotions, sortedPerformances); + } + + private List findPerformancesByGenre(HomeFindRequest homeFindRequest) { + Genre genre = homeFindRequest.genre(); + + if (genre != null) { + return performanceRepository.findByGenre(genre); + } + + return performanceRepository.findAll(); + } + + private List findAllPromotionsSortedByCarouselNumber() { + return promotionUseCase.findAllPromotions() + .stream() + .sorted(Comparator.comparing(Promotion::getCarouselNumber, Comparator.comparingInt(Enum::ordinal))) + .map(HomePromotionDetail::from) + .toList(); + } +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/PerformanceService.java b/src/main/java/com/beat/domain/performance/application/PerformanceService.java index e27cb59e..e1352dda 100644 --- a/src/main/java/com/beat/domain/performance/application/PerformanceService.java +++ b/src/main/java/com/beat/domain/performance/application/PerformanceService.java @@ -3,7 +3,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; -import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -23,10 +22,6 @@ import com.beat.domain.performance.application.dto.create.PerformanceImageResponse; import com.beat.domain.performance.application.dto.create.ScheduleResponse; import com.beat.domain.performance.application.dto.create.StaffResponse; -import com.beat.domain.performance.application.dto.home.HomePerformanceDetail; -import com.beat.domain.performance.application.dto.home.HomePromotionDetail; -import com.beat.domain.performance.application.dto.home.HomeRequest; -import com.beat.domain.performance.application.dto.home.HomeResponse; import com.beat.domain.performance.application.dto.makerPerformance.MakerPerformanceDetailResponse; import com.beat.domain.performance.application.dto.makerPerformance.MakerPerformanceResponse; import com.beat.domain.performance.application.dto.modify.PerformanceModifyDetailResponse; @@ -41,8 +36,6 @@ import com.beat.domain.performance.domain.PerformanceImage; import com.beat.domain.performance.exception.PerformanceErrorCode; import com.beat.domain.performance.port.in.PerformanceUseCase; -import com.beat.domain.promotion.dao.PromotionRepository; -import com.beat.domain.promotion.domain.Promotion; import com.beat.domain.schedule.application.ScheduleService; import com.beat.domain.schedule.dao.ScheduleRepository; import com.beat.domain.schedule.domain.Schedule; @@ -66,7 +59,6 @@ public class PerformanceService implements PerformanceUseCase { private final CastRepository castRepository; private final StaffRepository staffRepository; private final ScheduleService scheduleService; - private final PromotionRepository promotionRepository; private final MemberRepository memberRepository; private final UserRepository userRepository; private final BookingRepository bookingRepository; @@ -81,62 +73,38 @@ public PerformanceDetailResponse getPerformanceDetail(Long performanceId) { .stream() .map(schedule -> { int dueDate = scheduleService.calculateDueDate(schedule); - return PerformanceDetailScheduleResponse.of( - schedule.getId(), - schedule.getPerformanceDate(), - schedule.getScheduleNumber().name(), - dueDate, - schedule.isBooking() - ); + return PerformanceDetailScheduleResponse.of(schedule.getId(), schedule.getPerformanceDate(), + schedule.getScheduleNumber().name(), dueDate, schedule.isBooking()); }) .collect(Collectors.toList()); int minDueDate = scheduleService.getMinDueDate(scheduleRepository.findAllByPerformanceId(performanceId)); - List castList = castRepository.findByPerformanceId(performanceId).stream() - .map(cast -> PerformanceDetailCastResponse.of( - cast.getId(), - cast.getCastName(), - cast.getCastRole(), - cast.getCastPhoto() - )).collect(Collectors.toList()); - - List staffList = staffRepository.findByPerformanceId(performanceId).stream() - .map(staff -> PerformanceDetailStaffResponse.of( - staff.getId(), - staff.getStaffName(), - staff.getStaffRole(), - staff.getStaffPhoto() - )).collect(Collectors.toList()); + List castList = castRepository.findByPerformanceId(performanceId) + .stream() + .map(cast -> PerformanceDetailCastResponse.of(cast.getId(), cast.getCastName(), cast.getCastRole(), + cast.getCastPhoto())) + .collect(Collectors.toList()); + + List staffList = staffRepository.findByPerformanceId(performanceId) + .stream() + .map(staff -> PerformanceDetailStaffResponse.of(staff.getId(), staff.getStaffName(), staff.getStaffRole(), + staff.getStaffPhoto())) + .collect(Collectors.toList()); List performanceImageList = performanceImageRepository.findAllByPerformanceId( - performanceId).stream() - .map(image -> PerformanceDetailImageResponse.of( - image.getId(), - image.getPerformanceImage() - )) + performanceId) + .stream() + .map(image -> PerformanceDetailImageResponse.of(image.getId(), image.getPerformanceImage())) .collect(Collectors.toList()); log.info("Successfully completed getPerformanceDetail for performanceId: {}", performanceId); - return PerformanceDetailResponse.of( - performance.getId(), - performance.getPerformanceTitle(), - performance.getPerformancePeriod(), - scheduleList, - performance.getTicketPrice(), - performance.getGenre().name(), - performance.getPosterImage(), - performance.getRunningTime(), - performance.getPerformanceVenue(), - performance.getPerformanceDescription(), - performance.getPerformanceAttentionNote(), - performance.getPerformanceContact(), - performance.getPerformanceTeamName(), - castList, - staffList, - minDueDate, - performanceImageList - ); + return PerformanceDetailResponse.of(performance.getId(), performance.getPerformanceTitle(), + performance.getPerformancePeriod(), scheduleList, performance.getTicketPrice(), + performance.getGenre().name(), performance.getPosterImage(), performance.getRunningTime(), + performance.getPerformanceVenue(), performance.getPerformanceDescription(), + performance.getPerformanceAttentionNote(), performance.getPerformanceContact(), + performance.getPerformanceTeamName(), castList, staffList, minDueDate, performanceImageList); } @Transactional(readOnly = true) @@ -145,129 +113,39 @@ public BookingPerformanceDetailResponse getBookingPerformanceDetail(Long perform .orElseThrow(() -> new NotFoundException(PerformanceErrorCode.PERFORMANCE_NOT_FOUND)); List scheduleList = scheduleRepository.findByPerformanceId( - performanceId).stream() - .map(schedule -> { - int dueDate = scheduleService.calculateDueDate(schedule); - return BookingPerformanceDetailScheduleResponse.of( - schedule.getId(), - schedule.getPerformanceDate(), - schedule.getScheduleNumber().name(), - scheduleService.getAvailableTicketCount(schedule), - schedule.isBooking(), - dueDate - ); - }).collect(Collectors.toList()); - - return BookingPerformanceDetailResponse.of( - performance.getId(), - performance.getPerformanceTitle(), - performance.getPerformancePeriod(), - scheduleList, - performance.getTicketPrice(), - performance.getGenre().name(), - performance.getPosterImage(), - performance.getPerformanceVenue(), + performanceId).stream().map(schedule -> { + int dueDate = scheduleService.calculateDueDate(schedule); + return BookingPerformanceDetailScheduleResponse.of(schedule.getId(), schedule.getPerformanceDate(), + schedule.getScheduleNumber().name(), scheduleService.getAvailableTicketCount(schedule), + schedule.isBooking(), dueDate); + }).collect(Collectors.toList()); + + return BookingPerformanceDetailResponse.of(performance.getId(), performance.getPerformanceTitle(), + performance.getPerformancePeriod(), scheduleList, performance.getTicketPrice(), + performance.getGenre().name(), performance.getPosterImage(), performance.getPerformanceVenue(), performance.getPerformanceTeamName(), - performance.getBankName() != null ? performance.getBankName().name() : null, - performance.getAccountNumber(), - performance.getAccountHolder() - ); - } - - @Transactional(readOnly = true) - public HomeResponse getHomePerformanceList(HomeRequest homeRequest) { - List performances; - - if (homeRequest.genre() != null) { - performances = performanceRepository.findByGenre(homeRequest.genre()); - } else { - performances = performanceRepository.findAll(); - } - - if (performances.isEmpty()) { - List promotions = getPromotions(); - return HomeResponse.of(promotions, new ArrayList<>()); - } - - List performanceDetails = performances.stream() - .map(performance -> { - List schedules = scheduleRepository.findByPerformanceId(performance.getId()); - int minDueDate = scheduleService.getMinDueDate(schedules); - - return HomePerformanceDetail.of( - performance.getId(), - performance.getPerformanceTitle(), - performance.getPerformancePeriod(), - performance.getTicketPrice(), - minDueDate, - performance.getGenre().name(), - performance.getPosterImage(), - performance.getPerformanceVenue() - ); - }) - .collect(Collectors.toList()); - - List positiveDueDates = performanceDetails.stream() - .filter(detail -> detail.dueDate() >= 0) - .sorted((p1, p2) -> Integer.compare(p1.dueDate(), p2.dueDate())) - .collect(Collectors.toList()); - - List negativeDueDates = performanceDetails.stream() - .filter(detail -> detail.dueDate() < 0) - .sorted((p1, p2) -> Integer.compare(p2.dueDate(), p1.dueDate())) - .collect(Collectors.toList()); - - positiveDueDates.addAll(negativeDueDates); - - List promotions = getPromotions(); - - return HomeResponse.of(promotions, positiveDueDates); - } - - private List getPromotions() { - List promotionList = promotionRepository.findAll(); - return promotionList.stream() - .map(promotion -> { - Long performanceId = null; - if (promotion.getPerformance() != null) { - performanceId = promotion.getPerformance().getId(); - } - return HomePromotionDetail.of( - promotion.getId(), - promotion.getPromotionPhoto(), - performanceId, - promotion.getRedirectUrl(), - promotion.isExternal() - ); - }) - .collect(Collectors.toList()); + performance.getBankName() != null ? performance.getBankName().name() : null, performance.getAccountNumber(), + performance.getAccountHolder()); } @Transactional(readOnly = true) public MakerPerformanceResponse getMemberPerformances(Long memberId) { - Member member = memberRepository.findById(memberId).orElseThrow( - () -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND)); + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new NotFoundException(MemberErrorCode.MEMBER_NOT_FOUND)); - Users user = userRepository.findById(member.getUser().getId()).orElseThrow( - () -> new NotFoundException(UserErrorCode.USER_NOT_FOUND)); + Users user = userRepository.findById(member.getUser().getId()) + .orElseThrow(() -> new NotFoundException(UserErrorCode.USER_NOT_FOUND)); List performances = performanceRepository.findByUsersId(user.getId()); - List performanceDetails = performances.stream() - .map(performance -> { - List schedules = scheduleRepository.findByPerformanceId(performance.getId()); - int minDueDate = scheduleService.getMinDueDate(schedules); - - return MakerPerformanceDetailResponse.of( - performance.getId(), - performance.getGenre().name(), - performance.getPerformanceTitle(), - performance.getPosterImage(), - performance.getPerformancePeriod(), - minDueDate - ); - }) - .collect(Collectors.toList()); + List performanceDetails = performances.stream().map(performance -> { + List schedules = scheduleRepository.findByPerformanceId(performance.getId()); + int minDueDate = scheduleService.getMinDueDate(schedules); + + return MakerPerformanceDetailResponse.of(performance.getId(), performance.getGenre().name(), + performance.getPerformanceTitle(), performance.getPosterImage(), performance.getPerformancePeriod(), + minDueDate); + }).collect(Collectors.toList()); List positiveDueDates = performanceDetails.stream() .filter(detail -> detail.minDueDate() >= 0) @@ -290,7 +168,7 @@ public Performance findById(Long performanceId) { return performanceRepository.findById(performanceId) .orElseThrow(() -> new NotFoundException(PerformanceErrorCode.PERFORMANCE_NOT_FOUND)); } - + @Transactional public PerformanceModifyDetailResponse getPerformanceEdit(Long memberId, Long performanceId) { Member member = memberRepository.findById(memberId) @@ -321,64 +199,33 @@ private PerformanceModifyDetailResponse mapToPerformanceEditResponse(Performance List schedules, List casts, List staffs, List performanceImages, boolean isBookerExist) { List scheduleResponses = schedules.stream() - .map(schedule -> ScheduleResponse.of( - schedule.getId(), - schedule.getPerformanceDate(), - schedule.getTotalTicketCount(), - calculateDueDate(schedule.getPerformanceDate()), - schedule.getScheduleNumber() - )) + .map(schedule -> ScheduleResponse.of(schedule.getId(), schedule.getPerformanceDate(), + schedule.getTotalTicketCount(), calculateDueDate(schedule.getPerformanceDate()), + schedule.getScheduleNumber())) .collect(Collectors.toList()); List castResponses = casts.stream() - .map(cast -> CastResponse.of( - cast.getId(), - cast.getCastName(), - cast.getCastRole(), - cast.getCastPhoto() - )) + .map(cast -> CastResponse.of(cast.getId(), cast.getCastName(), cast.getCastRole(), cast.getCastPhoto())) .collect(Collectors.toList()); List staffResponses = staffs.stream() - .map(staff -> StaffResponse.of( - staff.getId(), - staff.getStaffName(), - staff.getStaffRole(), - staff.getStaffPhoto() - )) + .map(staff -> StaffResponse.of(staff.getId(), staff.getStaffName(), staff.getStaffRole(), + staff.getStaffPhoto())) .collect(Collectors.toList()); List performanceImageResponses = performanceImages.stream() - .map(performanceImage -> PerformanceImageResponse.of( - performanceImage.getId(), - performanceImage.getPerformanceImage() - )) + .map(performanceImage -> PerformanceImageResponse.of(performanceImage.getId(), + performanceImage.getPerformanceImage())) .collect(Collectors.toList()); - return PerformanceModifyDetailResponse.of( - performance.getUsers().getId(), - performance.getId(), - performance.getPerformanceTitle(), - performance.getGenre(), - performance.getRunningTime(), - performance.getPerformanceDescription(), - performance.getPerformanceAttentionNote(), - performance.getBankName(), - performance.getAccountNumber(), - performance.getAccountHolder(), - performance.getPosterImage(), - performance.getPerformanceTeamName(), - performance.getPerformanceVenue(), - performance.getPerformanceContact(), - performance.getPerformancePeriod(), - performance.getTicketPrice(), - performance.getTotalScheduleCount(), - isBookerExist, - scheduleResponses, - castResponses, - staffResponses, - performanceImageResponses - ); + return PerformanceModifyDetailResponse.of(performance.getUsers().getId(), performance.getId(), + performance.getPerformanceTitle(), performance.getGenre(), performance.getRunningTime(), + performance.getPerformanceDescription(), performance.getPerformanceAttentionNote(), + performance.getBankName(), performance.getAccountNumber(), performance.getAccountHolder(), + performance.getPosterImage(), performance.getPerformanceTeamName(), performance.getPerformanceVenue(), + performance.getPerformanceContact(), performance.getPerformancePeriod(), performance.getTicketPrice(), + performance.getTotalScheduleCount(), isBookerExist, scheduleResponses, castResponses, staffResponses, + performanceImageResponses); } private int calculateDueDate(LocalDateTime performanceDate) { diff --git a/src/main/java/com/beat/domain/performance/application/dto/home/HomeFindAllResponse.java b/src/main/java/com/beat/domain/performance/application/dto/home/HomeFindAllResponse.java new file mode 100644 index 00000000..1117fd4b --- /dev/null +++ b/src/main/java/com/beat/domain/performance/application/dto/home/HomeFindAllResponse.java @@ -0,0 +1,12 @@ +package com.beat.domain.performance.application.dto.home; + +import java.util.List; + +public record HomeFindAllResponse( + List promotionList, + List performanceList +) { + public static HomeFindAllResponse of(List promotionList, List performanceList) { + return new HomeFindAllResponse(promotionList, performanceList); + } +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/home/HomeRequest.java b/src/main/java/com/beat/domain/performance/application/dto/home/HomeFindRequest.java similarity index 70% rename from src/main/java/com/beat/domain/performance/application/dto/home/HomeRequest.java rename to src/main/java/com/beat/domain/performance/application/dto/home/HomeFindRequest.java index 841c8f08..3431ad80 100644 --- a/src/main/java/com/beat/domain/performance/application/dto/home/HomeRequest.java +++ b/src/main/java/com/beat/domain/performance/application/dto/home/HomeFindRequest.java @@ -2,5 +2,5 @@ import com.beat.domain.performance.domain.Genre; -public record HomeRequest(Genre genre) { -} +public record HomeFindRequest(Genre genre) { +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/home/HomePerformanceDetail.java b/src/main/java/com/beat/domain/performance/application/dto/home/HomePerformanceDetail.java index 1417cfb4..71dbefc4 100644 --- a/src/main/java/com/beat/domain/performance/application/dto/home/HomePerformanceDetail.java +++ b/src/main/java/com/beat/domain/performance/application/dto/home/HomePerformanceDetail.java @@ -1,16 +1,28 @@ package com.beat.domain.performance.application.dto.home; +import com.beat.domain.performance.domain.Performance; + public record HomePerformanceDetail( - Long performanceId, - String performanceTitle, - String performancePeriod, - int ticketPrice, - int dueDate, - String genre, - String posterImage, - String performanceVenue + Long performanceId, + String performanceTitle, + String performancePeriod, + int ticketPrice, + int dueDate, + String genre, + String posterImage, + String performanceVenue ) { - public static HomePerformanceDetail of(Long performanceId, String performanceTitle, String performancePeriod, int ticketPrice, int dueDate, String genre, String posterImage, String performanceVenue) { - return new HomePerformanceDetail(performanceId, performanceTitle, performancePeriod, ticketPrice, dueDate, genre, posterImage, performanceVenue); - } -} + + public static HomePerformanceDetail of(Performance performance, int minDueDate) { + return new HomePerformanceDetail( + performance.getId(), + performance.getPerformanceTitle(), + performance.getPerformancePeriod(), + performance.getTicketPrice(), + minDueDate, + performance.getGenre().name(), + performance.getPosterImage(), + performance.getPerformanceVenue() + ); + } +} \ No newline at end of file diff --git a/src/main/java/com/beat/domain/performance/application/dto/home/HomePromotionDetail.java b/src/main/java/com/beat/domain/performance/application/dto/home/HomePromotionDetail.java index 6cdd47a6..cf49a643 100644 --- a/src/main/java/com/beat/domain/performance/application/dto/home/HomePromotionDetail.java +++ b/src/main/java/com/beat/domain/performance/application/dto/home/HomePromotionDetail.java @@ -1,13 +1,19 @@ package com.beat.domain.performance.application.dto.home; -public record HomePromotionDetail( - Long promotionId, - String promotionPhoto, - Long performanceId, - String redirectUrl, - boolean isExternal -) { - public static HomePromotionDetail of(Long promotionId, String promotionPhoto, Long performanceId, String redirectUrl, boolean isExternal) { - return new HomePromotionDetail(promotionId, promotionPhoto, performanceId, redirectUrl, isExternal); - } +import com.beat.domain.promotion.domain.CarouselNumber; +import com.beat.domain.promotion.domain.Promotion; + +public record HomePromotionDetail(Long promotionId, String promotionPhoto, Long performanceId, String redirectUrl, + boolean isExternal, CarouselNumber carouselNumber) { + + public static HomePromotionDetail from(Promotion promotion) { + Long performanceId = null; + + if (promotion.getPerformance() != null) { + performanceId = promotion.getPerformance().getId(); + } + + return new HomePromotionDetail(promotion.getId(), promotion.getPromotionPhoto(), performanceId, + promotion.getRedirectUrl(), promotion.isExternal(), promotion.getCarouselNumber()); + } } diff --git a/src/main/java/com/beat/domain/performance/application/dto/home/HomeResponse.java b/src/main/java/com/beat/domain/performance/application/dto/home/HomeResponse.java deleted file mode 100644 index c3d963b4..00000000 --- a/src/main/java/com/beat/domain/performance/application/dto/home/HomeResponse.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.beat.domain.performance.application.dto.home; - -import java.util.List; - -public record HomeResponse( - List promotionList, - List performanceList -) { - public static HomeResponse of(List promotionList, List performanceList) { - return new HomeResponse(promotionList, performanceList); - } -} diff --git a/src/main/java/com/beat/domain/promotion/application/PromotionService.java b/src/main/java/com/beat/domain/promotion/application/PromotionService.java index 35ecd364..dff92653 100644 --- a/src/main/java/com/beat/domain/promotion/application/PromotionService.java +++ b/src/main/java/com/beat/domain/promotion/application/PromotionService.java @@ -1,6 +1,6 @@ package com.beat.domain.promotion.application; -import com.beat.admin.application.dto.request.CarouselProcessRequest.PromotionModifyRequest; +import com.beat.admin.application.dto.request.CarouselHandleRequest.PromotionModifyRequest; import com.beat.domain.performance.domain.Performance; import com.beat.domain.promotion.dao.PromotionRepository; import com.beat.domain.promotion.domain.CarouselNumber; diff --git a/src/main/java/com/beat/domain/promotion/port/in/PromotionUseCase.java b/src/main/java/com/beat/domain/promotion/port/in/PromotionUseCase.java index 1ad8acd6..92ce078c 100644 --- a/src/main/java/com/beat/domain/promotion/port/in/PromotionUseCase.java +++ b/src/main/java/com/beat/domain/promotion/port/in/PromotionUseCase.java @@ -1,6 +1,6 @@ package com.beat.domain.promotion.port.in; -import com.beat.admin.application.dto.request.CarouselProcessRequest.PromotionModifyRequest; +import com.beat.admin.application.dto.request.CarouselHandleRequest.PromotionModifyRequest; import com.beat.domain.performance.domain.Performance; import com.beat.domain.promotion.domain.CarouselNumber; import com.beat.domain.promotion.domain.Promotion; diff --git a/src/main/java/com/beat/domain/schedule/application/ScheduleService.java b/src/main/java/com/beat/domain/schedule/application/ScheduleService.java index ed252e51..838a17b0 100644 --- a/src/main/java/com/beat/domain/schedule/application/ScheduleService.java +++ b/src/main/java/com/beat/domain/schedule/application/ScheduleService.java @@ -46,12 +46,6 @@ public TicketAvailabilityResponse findTicketAvailability(Long scheduleId, Ticket ); } - private void validateRequest(Long scheduleId, TicketAvailabilityRequest ticketAvailabilityRequest) { - if (ticketAvailabilityRequest.purchaseTicketCount() <= 0 || scheduleId <= 0) { - throw new BadRequestException(ScheduleErrorCode.INVALID_DATA_FORMAT); - } - } - public int getAvailableTicketCount(Schedule schedule) { return schedule.getTotalTicketCount() - schedule.getSoldTicketCount(); } @@ -61,6 +55,11 @@ public int calculateDueDate(Schedule schedule) { return dueDate; } + public int getMinDueDateForPerformance(Long performanceId) { + List schedules = scheduleRepository.findByPerformanceId(performanceId); + return getMinDueDate(schedules); + } + public int getMinDueDate(List schedules) { OptionalInt minPositiveDueDate = schedules.stream() .mapToInt(this::calculateDueDate) @@ -77,4 +76,9 @@ public int getMinDueDate(List schedules) { } } + private void validateRequest(Long scheduleId, TicketAvailabilityRequest ticketAvailabilityRequest) { + if (ticketAvailabilityRequest.purchaseTicketCount() <= 0 || scheduleId <= 0) { + throw new BadRequestException(ScheduleErrorCode.INVALID_DATA_FORMAT); + } + } }