-
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.
[refactor] #221 - 메인페이지에서 캐러셀 응답 시 캐러셀 번호로 정렬해서 주도록 변경 및 메인 페이지 조회 코드…
… 최적화 (#222) * [#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): 음수는 내림차순, 양수는 오름차순으로 정렬하도록 수정
- Loading branch information
1 parent
2846432
commit 2dbb3a4
Showing
20 changed files
with
282 additions
and
310 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
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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/beat/admin/application/dto/request/PromotionHandleRequest.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
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
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
33 changes: 33 additions & 0 deletions
33
src/main/java/com/beat/domain/performance/api/HomeApi.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,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<SuccessResponse<HomeFindAllResponse>> getHomePerformanceList( | ||
@RequestParam(required = false) Genre genre); | ||
} |
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
71 changes: 71 additions & 0 deletions
71
src/main/java/com/beat/domain/performance/application/HomeService.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,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<Performance> performances = findPerformancesByGenre(homeFindRequest); | ||
List<HomePromotionDetail> promotions = findAllPromotionsSortedByCarouselNumber(); | ||
|
||
if (performances.isEmpty()) { | ||
return HomeFindAllResponse.of(promotions, new ArrayList<>()); | ||
} | ||
|
||
List<HomePerformanceDetail> sortedPerformances = performances.stream() | ||
.map(performance -> { | ||
int minDueDate = scheduleService.getMinDueDateForPerformance(performance.getId()); | ||
return HomePerformanceDetail.of(performance, minDueDate); | ||
}) | ||
.sorted(Comparator.<HomePerformanceDetail>comparingInt(detail -> detail.dueDate() < 0 ? 1 : 0) | ||
.thenComparingInt(detail -> Math.abs(detail.dueDate()))) | ||
.toList(); | ||
|
||
return HomeFindAllResponse.of(promotions, sortedPerformances); | ||
} | ||
|
||
private List<Performance> findPerformancesByGenre(HomeFindRequest homeFindRequest) { | ||
Genre genre = homeFindRequest.genre(); | ||
|
||
if (genre != null) { | ||
return performanceRepository.findByGenre(genre); | ||
} | ||
|
||
return performanceRepository.findAll(); | ||
} | ||
|
||
private List<HomePromotionDetail> findAllPromotionsSortedByCarouselNumber() { | ||
return promotionUseCase.findAllPromotions() | ||
.stream() | ||
.sorted(Comparator.comparing(Promotion::getCarouselNumber, Comparator.comparingInt(Enum::ordinal))) | ||
.map(HomePromotionDetail::from) | ||
.toList(); | ||
} | ||
} |
Oops, something went wrong.