-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[refactor] #221 - 메인페이지에서 캐러셀 응답 시 캐러셀 번호로 정렬해서 주도록 변경 및 메인 페이지 조회 코드 최적화 #222
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8c811e2
[#221] rename: DTO 이름 변경 및 import문 최신화
hoonyworld 753e583
[#221] chore(AdminApi): 통일성을 위해 mapping 어노테이션 삭제
hoonyworld 96bd2c3
[#221] rename(HomeFindRequest): 요청 DTO 네이밍 구체화
hoonyworld fc06169
[#221] rename(HomeFindAllResponse): 응답 DTO 네이밍 구체화
hoonyworld 05df788
[#221] refactor(PerformanceService): getHomePerformanceList, getPromo…
hoonyworld b6110a5
[#221] feat(HomeService): 공연 및 홍보 조회 서비스 로직 최적화
hoonyworld 91327b2
[#221] feat(ScheduleService): 공연의 회차 중 가장 dueDate가 적은 회차의 dueDate를 반환…
hoonyworld 0539206
[#221] refactor(HomePromotionDetail): 정적 팩토리 메서드 내에서 초기화해서 return 하도록 변경
hoonyworld 42162eb
[#221] refactor(HomePerformanceDetail): 정적 팩토리 메서드 내에서 초기화해서 return 하…
hoonyworld 2618536
[#221] feat(HomeApi): Home API 스웨거 명세서 작성
hoonyworld 699a0c8
[#221] refactor(HomeController): 로직 최적화
hoonyworld e43ce63
[#221] fix(HomeService): 음수는 내림차순, 양수는 오름차순으로 정렬하도록 수정
hoonyworld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.comparingInt(HomePerformanceDetail::dueDate) | ||
.reversed() | ||
.thenComparingInt(detail -> detail.dueDate() >= 0 ? -1 : 1)) | ||
.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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
홈화면에서 공연 정렬 기준은 duedate가 양수일 경우 오름차순, 이후 음수는 내림차순입니다!
예를 들어 0, 2, 4, 15, -1, -4, -10 이런식으로요. 지금 코드는 양수인 경우에도 내림차순으로 정렬하고 있는 것 같습니다ㅠㅠ
이렇게 바꾸면 어떨까요?
로컬 테스트하실 때 과거 공연과 미래 공연 섞어서 홈화면 잘 정렬되는지 확인해주시면 좋을 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 놓쳤던 부분이였네요!!
그런데, 지금 보내주신 코드도 음수 정렬의 경우 오름차순 정렬을 해주고 있어서 다음과 같이 반영하겠습니다!
절댓값을 비교해서 정렬을 해주는 로직을 도입하여 양수는 그대로 오름차순, 음수는 절댓값을 씌워서 정렬하면 내림차순으로 정렬되는 점을 이용했습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pr 내용에도 추가했습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 처음엔 절댓값을 씌우는 방식을 고려했는데 더 알아본 결과 comparator가 원래 양수는 오름차순, 음수는 내림차순으로 정렬하더라구요!
https://bono039.tistory.com/847
링크 참고해주세요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comparator는 양수는 오름차순, 음수는 내림차순으로 정렬하는 것이 아닌 양수든 음수든 결국 같이 오름차순 or 내림차순으로 정렬하는 로직입니다.
Comparator.compare(a, b)에서:
예를 들어, a=-2, b=-4라 가정할 때 a-b 로직을 사용하면
-2 - (-4) = +2
이므로 양수기 때문에 -4가 앞에오고 -2는 뒤로 가게 됩니다.이때는 오름차순 정렬이 되게됩니다.
반면, a=-2, b=-4라 가정할 때 b-a 로직을 사용하면
-4 - (-2) = -2
이므로 음수기 때문에 -2가 앞에오고 -4는 뒤로 가게 됩니다.이때는 내림차순 졍렬이 되게됩니다.
따라서 a-b냐 b-a냐에 따라 양수든 음수든 오름차순으로 혹은 내림차순으로 정렬이 되게됩니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엇 그렇군요! 제가 잘못 알고 있었나보네요 감사합니다~