From 3428bfe4de5d79fa5283fc95d5ecb027cb22ecfe Mon Sep 17 00:00:00 2001 From: Ethan Date: Mon, 19 Feb 2024 23:26:44 +0900 Subject: [PATCH] =?UTF-8?q?reviewCount=EA=B0=80=200=EC=9D=B8=20=ED=95=AD?= =?UTF-8?q?=EB=AA=A9=EC=9D=B4=20=EC=A1=B0=ED=9A=8C=EA=B0=80=20=EB=90=98?= =?UTF-8?q?=EB=A9=B4=20=EC=A0=9C=EC=99=B8=EB=90=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20(#722)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: reviewCount가 0인 항목이 조회가 되면 제외되도록 구현 * refactor: count 할 때 reviewStatus가 포함되도록 변경 --- .../repository/RankQuerydslRepository.java | 2 + .../repository/RunnerPostPageRepository.java | 3 +- .../RankQuerydslRepositoryTest.java | 21 +++++++++ .../query/service/RankQueryServiceTest.java | 43 ++++++++++++++++++- .../service/RunnerPostQueryServiceTest.java | 16 +++---- 5 files changed, 75 insertions(+), 10 deletions(-) diff --git a/backend/baton/src/main/java/touch/baton/domain/member/query/repository/RankQuerydslRepository.java b/backend/baton/src/main/java/touch/baton/domain/member/query/repository/RankQuerydslRepository.java index 06f741d2b..0e5456587 100644 --- a/backend/baton/src/main/java/touch/baton/domain/member/query/repository/RankQuerydslRepository.java +++ b/backend/baton/src/main/java/touch/baton/domain/member/query/repository/RankQuerydslRepository.java @@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; import touch.baton.domain.member.command.Supporter; +import touch.baton.domain.member.command.vo.ReviewCount; import java.util.List; @@ -19,6 +20,7 @@ public class RankQuerydslRepository { public List findMostReviewSupporterByCount(final int count) { return jpaQueryFactory.selectFrom(supporter) .join(supporter.member, member).fetchJoin() + .where(supporter.reviewCount.ne(new ReviewCount(0))) .orderBy(supporter.reviewCount.value.desc()) .limit(count) .fetch(); diff --git a/backend/baton/src/main/java/touch/baton/domain/runnerpost/query/repository/RunnerPostPageRepository.java b/backend/baton/src/main/java/touch/baton/domain/runnerpost/query/repository/RunnerPostPageRepository.java index 086afbc69..9e6566e49 100644 --- a/backend/baton/src/main/java/touch/baton/domain/runnerpost/query/repository/RunnerPostPageRepository.java +++ b/backend/baton/src/main/java/touch/baton/domain/runnerpost/query/repository/RunnerPostPageRepository.java @@ -45,7 +45,8 @@ public Page pageByReviewStatusAndTagReducedName(final Long previousL .where(tag.tagReducedName.eq(tagReducedName)); } - final JPAQuery countQuery = jpaQueryFactory.selectFrom(runnerPost); + final JPAQuery countQuery = jpaQueryFactory.selectFrom(runnerPost) + .where(reviewStatusEq(reviewStatus)); if (tagReducedName != null) { countQuery.leftJoin(runnerPost.runnerPostTags.runnerPostTags, runnerPostTag) diff --git a/backend/baton/src/test/java/touch/baton/domain/member/query/repository/RankQuerydslRepositoryTest.java b/backend/baton/src/test/java/touch/baton/domain/member/query/repository/RankQuerydslRepositoryTest.java index 0097ee79e..a517d4a29 100644 --- a/backend/baton/src/test/java/touch/baton/domain/member/query/repository/RankQuerydslRepositoryTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/member/query/repository/RankQuerydslRepositoryTest.java @@ -37,4 +37,25 @@ void findMostReviewSupporterByCount() { () -> assertThat(actual.get(1).getReviewCount().getValue()).isEqualTo(4) ); } + + @DisplayName("Supporter의 count가 안되더라도 ReviewCount가 0이면 조회되지 않는다.") + @Test + void findMostReviewSupporterByCount_having_count_is_zero() { + // given + persistSupporter(new ReviewCount(0), MemberFixture.createEthan()); + persistSupporter(new ReviewCount(3), MemberFixture.createHyena()); + persistSupporter(new ReviewCount(8), MemberFixture.createDitoo()); + + // when + final int count = 3; + final int zeroCount = 1; + final List actual = rankQueryDslRepository.findMostReviewSupporterByCount(count); + + // then + assertAll( + () -> assertThat(actual).hasSize(count - zeroCount), + () -> assertThat(actual.get(0).getReviewCount().getValue()).isEqualTo(8), + () -> assertThat(actual.get(1).getReviewCount().getValue()).isEqualTo(3) + ); + } } diff --git a/backend/baton/src/test/java/touch/baton/domain/member/query/service/RankQueryServiceTest.java b/backend/baton/src/test/java/touch/baton/domain/member/query/service/RankQueryServiceTest.java index 306518e61..cf2fee683 100644 --- a/backend/baton/src/test/java/touch/baton/domain/member/query/service/RankQueryServiceTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/member/query/service/RankQueryServiceTest.java @@ -30,7 +30,6 @@ void setUp() { @Test void readMostReviewSupporter() { // given - for (int reviewedCount = 0; reviewedCount < 5; reviewedCount++) { persistSupporter(new ReviewCount(reviewedCount), MemberFixture.create(memberName("member" + reviewedCount))); } @@ -73,6 +72,48 @@ void readMostReviewSupporter() { ); } + @DisplayName("Supporter의 ReviewCount가 높은 순으로 count 개수 만큼 조회하고, 그 중 ReviewCount가 0이면 제외된다.") + @Test + void readMostReviewSupporter_when_has_zero_reviewCount() { + // given + final TechnicalTag javaTag = technicalTagQueryRepository.save(TechnicalTagFixture.createJava()); + final TechnicalTag springTag = technicalTagQueryRepository.save(TechnicalTagFixture.createSpring()); + final TechnicalTag reactTag = technicalTagQueryRepository.save(TechnicalTagFixture.createReact()); + + final Member fourthRankMember = persistMember(MemberFixture.create(memberName("fourth"))); + final List fourthRankMembersTechnicalTags = List.of(javaTag, springTag); + persistSupporter(new ReviewCount(12), fourthRankMember, fourthRankMembersTechnicalTags); + + final Member thirdRankMember = persistMember(MemberFixture.create(memberName("third"))); + final List thirdRankMembersTechnicalTags = List.of(javaTag, reactTag); + persistSupporter(new ReviewCount(13), thirdRankMember, thirdRankMembersTechnicalTags); + + final Member firstRankMember = persistMember(MemberFixture.create(memberName("first"))); + final List firstRankMembersTechnicalTags = List.of(javaTag, springTag); + persistSupporter(new ReviewCount(15), firstRankMember, firstRankMembersTechnicalTags); + + final Member secondRankMember = persistMember(MemberFixture.create(memberName("second"))); + final List secondRankMembersTechnicalTags = List.of(javaTag); + persistSupporter(new ReviewCount(14), secondRankMember, secondRankMembersTechnicalTags); + + final Member fifthRankMember = persistMember(MemberFixture.create(memberName("fifth"))); + final List fifthMembersTechnicalTags = List.of(reactTag); + persistSupporter(new ReviewCount(0), fifthRankMember, fifthMembersTechnicalTags); + + // when + final int maxCount = 5; + final RankResponses actual = rankQueryService.readMostReviewSupporter(maxCount); + + // then + assertAll( + () -> assertThat(actual.data()).hasSize(4), + () -> assertResponse(actual.data().get(0), 1, "first", 15), + () -> assertResponse(actual.data().get(1), 2, "second", 14), + () -> assertResponse(actual.data().get(2), 3, "third", 13), + () -> assertResponse(actual.data().get(3), 4, "fourth", 12) + ); + } + private static void assertResponse(final RankResponses.SupporterRank response, final int rank, final String memberName, final int reviewCount) { assertAll( () -> assertThat(response.rank()).isEqualTo(rank), diff --git a/backend/baton/src/test/java/touch/baton/domain/runnerpost/query/service/RunnerPostQueryServiceTest.java b/backend/baton/src/test/java/touch/baton/domain/runnerpost/query/service/RunnerPostQueryServiceTest.java index d291336ed..a848a283a 100644 --- a/backend/baton/src/test/java/touch/baton/domain/runnerpost/query/service/RunnerPostQueryServiceTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/runnerpost/query/service/RunnerPostQueryServiceTest.java @@ -77,7 +77,7 @@ void readRunnerPostByPageInfoAndTagNameAndReviewStatus_firstPage() { final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바"))); final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링"))); - final int totalJavaTagPost = 3; + final int totalJavaTagAndNotStartedPost = 2; final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create( hyenaRunner, @@ -124,7 +124,7 @@ void readRunnerPostByPageInfoAndTagNameAndReviewStatus_firstPage() { List.of(RunnerPostResponse.Simple.of(expectedRunnerPostTwo, 0L, runnerPostTags), RunnerPostResponse.Simple.of(expectedRunnerPostOne, 0L, runnerPostTags)), pageParams, - totalJavaTagPost + totalJavaTagAndNotStartedPost ); // then @@ -140,7 +140,7 @@ void readRunnerPostByPageInfoAndTagNameAndReviewStatus_middlePage() { final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바"))); final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링"))); - final int totalJavaTagPost = 4; + final int totalJavaTagAndNotStartedPost = 3; final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create( hyenaRunner, @@ -194,7 +194,7 @@ void readRunnerPostByPageInfoAndTagNameAndReviewStatus_middlePage() { List.of(RunnerPostResponse.Simple.of(expectedRunnerPostTwo, 0L, runnerPostTags), RunnerPostResponse.Simple.of(expectedRunnerPostOne, 0L, runnerPostTags)), pageParams, - totalJavaTagPost + totalJavaTagAndNotStartedPost ); // then @@ -210,7 +210,7 @@ void readRunnerPostByPageInfoAndReviewStatus_firstPage() { final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바"))); final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링"))); - final int totalPost = 4; + final int totalNotStartedPost = 3; final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create( hyenaRunner, @@ -260,7 +260,7 @@ void readRunnerPostByPageInfoAndReviewStatus_firstPage() { RunnerPostResponse.Simple.of(expectedRunnerPostTwo, 0L, runnerPostTags), RunnerPostResponse.Simple.of(expectedRunnerPostOne, 0L, runnerPostTags)), pageParams, - totalPost + totalNotStartedPost ); // then @@ -276,7 +276,7 @@ void readRunnerPostByPageInfoAndReviewStatus_middlePage() { final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바"))); final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링"))); - final int totalPost = 5; + final int notStartedPost = 4; final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create( hyenaRunner, @@ -332,7 +332,7 @@ void readRunnerPostByPageInfoAndReviewStatus_middlePage() { RunnerPostResponse.Simple.of(expectedRunnerPostTwo, 0L, runnerPostTags), RunnerPostResponse.Simple.of(expectedRunnerPostOne, 0L, runnerPostTags)), pageParams, - totalPost + notStartedPost ); // then