Skip to content

[feat] 작곡가 목록 응답에 storyPostCount, lastStoryPostAt 추가#92

Merged
k3vin7 merged 1 commit intomainfrom
fix/posts
Feb 28, 2026
Merged

[feat] 작곡가 목록 응답에 storyPostCount, lastStoryPostAt 추가#92
k3vin7 merged 1 commit intomainfrom
fix/posts

Conversation

@k3vin7
Copy link
Contributor

@k3vin7 k3vin7 commented Feb 28, 2026

Summary

  • GET /composers 응답에 storyPostCount, lastStoryPostAt 필드 추가
  • 단건 쿼리(GROUP BY)로 모든 작곡가의 STORY 게시글 통계를 한 번에 집계하여 N+1 방지
  • DRAFT 상태 또는 isBlocked 게시글은 집계에서 제외
  • 게시글이 없는 작곡가는 storyPostCount: 0, lastStoryPostAt: null 반환

Changes

  • StoryPostStatsDto 신규 레코드 추가
  • PostQueryRepository.findStoryPostStatsByAllComposers() 메서드 추가
  • ComposerResponseDtostoryPostCount, lastStoryPostAt 필드 추가
  • ComposerQueryService에서 통계 맵 일괄 조회 후 DTO 생성 시 주입
  • 컨트롤러 테스트, 서비스 테스트 업데이트

Test plan

  • ComposerQueryServiceTest.storyPostStats_returnedCorrectly — PUBLISHED만 집계, DRAFT 제외 확인
  • ComposerQueryControllerTest 두 엔드포인트 REST Docs 스니펫 생성 확인
  • GET /composers 응답에 storyPostCount, lastStoryPostAt 포함 여부 확인

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 작곡가 목록 조회 API(GET /composers)의 응답에 작곡가별 스토리 게시글 수와 가장 최근 게시글 작성 시각 정보를 추가하여 기능을 확장합니다. 이는 N+1 쿼리 문제를 해결하기 위해 모든 작곡가의 스토리 게시글 통계를 효율적으로 집계하는 방식으로 구현되었으며, 사용자에게 더 풍부한 정보를 제공하고 시스템 성능을 개선하는 데 기여합니다.

Highlights

  • API 응답 확장: GET /composers 응답에 작곡가별 스토리 게시글 수(storyPostCount) 및 가장 최근 게시글 작성 시각(lastStoryPostAt) 필드를 추가했습니다.
  • 성능 최적화: N+1 쿼리 문제를 방지하기 위해 모든 작곡가의 스토리 게시글 통계를 단일 쿼리로 효율적으로 집계하도록 구현했습니다.
  • 데이터 필터링: DRAFT 상태이거나 차단된 게시글은 통계 집계에서 제외되며, 스토리 게시글이 없는 작곡가는 storyPostCount: 0, lastStoryPostAt: null로 반환됩니다.
  • 새로운 DTO 및 쿼리 메서드: StoryPostStatsDto 레코드를 신규 추가하고, PostQueryRepositoryfindStoryPostStatsByAllComposers() 메서드를 추가하여 통계 조회를 담당하도록 했습니다.
  • 서비스 로직 및 테스트 업데이트: ComposerQueryService에서 통계 맵을 일괄 조회하여 ComposerResponseDto 생성 시 주입하도록 로직을 변경했으며, 컨트롤러 및 서비스 테스트를 업데이트하여 변경 사항을 검증했습니다.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/main/java/com/daramg/server/composer/application/ComposerQueryService.java
    • StoryPostStatsDtoPostQueryRepository를 임포트했습니다.
    • PostQueryRepository 의존성을 주입했습니다.
    • getAllComposers 메서드에서 postQueryRepository.findStoryPostStatsByAllComposers()를 호출하여 스토리 게시글 통계 맵을 가져오도록 변경했습니다.
    • ComposerResponseDto.from 호출 시 스토리 게시글 통계 정보를 전달하도록 수정했습니다.
  • src/main/java/com/daramg/server/composer/dto/ComposerResponseDto.java
    • StoryPostStatsDto, JsonInclude, Instant를 임포트했습니다.
    • storyPostCount (게시글 수) 및 lastStoryPostAt (최근 게시글 시각) 필드를 추가했습니다.
    • from 팩토리 메서드가 StoryPostStatsDto를 인자로 받도록 변경하고, 통계 정보가 없을 경우 기본값(0L, null)을 설정하도록 구현했습니다.
  • src/main/java/com/daramg/server/post/application/PostQueryService.java
    • getComposerWithPosts 메서드에서 ComposerResponseDto.from 호출 시 스토리 게시글 통계 정보를 null로 전달하도록 수정했습니다.
  • src/main/java/com/daramg/server/post/dto/StoryPostStatsDto.java
    • storyPostCountlastStoryPostAt 필드를 포함하는 StoryPostStatsDto 레코드를 새로 추가했습니다.
  • src/main/java/com/daramg/server/post/repository/PostQueryRepository.java
    • StoryPostStatsDtoMap을 임포트했습니다.
    • 모든 작곡가의 스토리 게시글 통계를 조회하는 findStoryPostStatsByAllComposers() 메서드 시그니처를 추가했습니다.
  • src/main/java/com/daramg/server/post/repository/PostQueryRepositoryImpl.java
    • StoryPostStatsDto, Tuple, Collectors를 임포트했습니다.
    • findStoryPostStatsByAllComposers() 메서드를 QueryDSL을 사용하여 구현하여, 작곡가별 스토리 게시글 통계를 효율적으로 집계했습니다.
  • src/test/java/com/daramg/server/composer/application/ComposerQueryServiceTest.java
    • PostStatus, StoryPost, PostCreateVo, PostRepository를 임포트했습니다.
    • PostRepository 의존성을 주입했습니다.
    • 스토리 게시글 통계 기능의 정확성을 검증하는 storyPostStats_returnedCorrectly 테스트 케이스를 추가했습니다.
  • src/test/java/com/daramg/server/composer/presentation/ComposerQueryControllerTest.java
    • 작곡가 목록 조회 API의 응답에 추가된 필드를 반영하도록 컨트롤러 테스트의 목업 데이터와 REST Docs 스니펫을 업데이트했습니다.
Activity
  • ComposerQueryServiceTest.storyPostStats_returnedCorrectly 테스트 케이스를 통해 PUBLISHED 상태의 스토리 게시글만 집계되고 DRAFT 게시글은 제외되는지 확인했습니다.
  • ComposerQueryControllerTest에서 두 엔드포인트에 대한 REST Docs 스니펫 생성을 확인했습니다.
  • GET /composers 응답에 storyPostCountlastStoryPostAt 필드가 올바르게 포함되는지 확인했습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

이번 PR은 작곡가 목록 조회 시 스토리 게시글 통계 정보를 추가하는 기능이네요. N+1 문제를 방지하기 위해 단일 쿼리로 모든 작곡가의 통계를 한 번에 집계하는 접근 방식이 좋습니다. 전반적으로 코드가 잘 작성되었지만, 몇 가지 개선할 점이 보입니다.

한 가지는 단일 작곡가 조회 API에서 통계 정보가 누락되어 API 간 데이터 정합성이 맞지 않는 부분입니다. 다른 하나는 QueryDSL을 더 효율적이고 관용적인 방법으로 사용할 수 있는 부분에 대한 제안입니다. 자세한 내용은 각 파일에 남긴 주석을 확인해주세요.

Composer composer = entityUtils.getEntity(composerId, Composer.class);
boolean isLiked = user != null && composerLikeRepository.existsByComposerIdAndUserId(composerId, user.getId());
ComposerResponseDto composerDto = ComposerResponseDto.from(composer, isLiked);
ComposerResponseDto composerDto = ComposerResponseDto.from(composer, isLiked, null);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

ComposerResponseDto.from 메서드 시그니처 변경으로 인해 null을 전달하도록 수정하신 것으로 보입니다. 하지만 이렇게 되면 /composers/{composerId}/posts 엔드포인트의 응답에서 storyPostCount는 항상 0, lastStoryPostAt은 항상 null이 되어 /composers 목록 조회 API와 데이터 정합성이 맞지 않게 됩니다.

단일 작곡가에 대한 통계도 조회하여 ComposerResponseDto를 생성할 때 함께 전달하는 것이 좋겠습니다. PostQueryRepository에 단일 작곡가의 통계를 조회하는 메서드를 추가하여 해결할 수 있습니다.

Comment on lines +192 to +212
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())
)
));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

현재 구현은 fetch()List<Tuple>을 가져온 후, stream을 사용해 Map으로 변환하고 있습니다. 이는 올바르게 동작하지만, QueryDSL의 transformgroupBy를 사용하면 더 간결하고 효율적인 코드를 작성할 수 있습니다. transform을 사용하면 중간 단계의 List 생성 없이 바로 Map을 생성할 수 있습니다.

아래와 같이 리팩토링하는 것을 고려해보세요.

Suggested change
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())
)
));
return queryFactory
.from(storyPost)
.where(
storyPost._super.isBlocked.isFalse()
.and(storyPost._super.postStatus.eq(PostStatus.PUBLISHED))
)
.groupBy(storyPost.primaryComposer.id)
.transform(com.querydsl.core.group.GroupBy.groupBy(storyPost.primaryComposer.id).as(
com.querydsl.core.types.Projections.constructor(StoryPostStatsDto.class,
storyPost._super.id.count(),
storyPost._super.createdAt.max()
)
));

@k3vin7 k3vin7 merged commit c9409df into main Feb 28, 2026
1 check passed
@k3vin7 k3vin7 deleted the fix/posts branch February 28, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant