-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] 작곡가 목록 응답에 storyPostCount, lastStoryPostAt 추가 #92
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
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/daramg/server/post/dto/StoryPostStatsDto.java
This file contains hidden or 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,5 @@ | ||
| package com.daramg.server.post.dto; | ||
|
|
||
| import java.time.Instant; | ||
|
|
||
| public record StoryPostStatsDto(long storyPostCount, Instant lastStoryPostAt) {} |
This file contains hidden or 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 hidden or 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,8 +10,10 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.daramg.server.post.domain.PostStatus; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.daramg.server.post.domain.QPost; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.daramg.server.post.domain.StoryPost; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.daramg.server.post.dto.StoryPostStatsDto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.daramg.server.composer.domain.QComposer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.querydsl.core.BooleanBuilder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.querydsl.core.Tuple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.querydsl.core.types.dsl.EntityPathBase; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.querydsl.jpa.JPAExpressions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.querydsl.jpa.impl.JPAQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -21,6 +23,8 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.ArrayList; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.stream.Collectors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static com.daramg.server.post.domain.QPost.post; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static com.daramg.server.post.domain.QPostScrap.postScrap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -183,6 +187,31 @@ public List<Post> getPostsByComposerIdWithPaging(Long composerId, PageRequestDto | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public Map<Long, StoryPostStatsDto> findStoryPostStatsByAllComposers() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Tuple> results = queryFactory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .select( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| storyPost.primaryComposer.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| storyPost._super.id.count(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| storyPost._super.createdAt.max() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .from(storyPost) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .where( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| storyPost._super.isBlocked.isFalse() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .and(storyPost._super.postStatus.eq(PostStatus.PUBLISHED)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .groupBy(storyPost.primaryComposer.id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .fetch(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return results.stream().collect(Collectors.toMap( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tuple -> tuple.get(storyPost.primaryComposer.id), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tuple -> new StoryPostStatsDto( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tuple.get(storyPost._super.id.count()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tuple.get(storyPost._super.createdAt.max()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+192
to
+212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 구현은 아래와 같이 리팩토링하는 것을 고려해보세요.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private <T extends Post> List<T> getAllPostsWithPaging( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PageRequestDto pageRequest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EntityPathBase<T> qEntity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file contains hidden or 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 hidden or 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
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.
ComposerResponseDto.from메서드 시그니처 변경으로 인해null을 전달하도록 수정하신 것으로 보입니다. 하지만 이렇게 되면/composers/{composerId}/posts엔드포인트의 응답에서storyPostCount는 항상 0,lastStoryPostAt은 항상null이 되어/composers목록 조회 API와 데이터 정합성이 맞지 않게 됩니다.단일 작곡가에 대한 통계도 조회하여
ComposerResponseDto를 생성할 때 함께 전달하는 것이 좋겠습니다.PostQueryRepository에 단일 작곡가의 통계를 조회하는 메서드를 추가하여 해결할 수 있습니다.