From 89a947b1c77d837e38721732c9e93cfe5cdd34fd Mon Sep 17 00:00:00 2001 From: Ethan Date: Sat, 17 Feb 2024 21:43:10 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20review=20=EC=99=84=EB=A3=8C=20?= =?UTF-8?q?=EC=8B=9C=20reviewCount=20=EC=A6=9D=EA=B0=80=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/touch/baton/domain/member/command/Supporter.java | 4 ++++ .../touch/baton/domain/member/command/vo/ReviewCount.java | 4 ++++ .../runnerpost/command/service/RunnerPostCommandService.java | 1 + 3 files changed, 9 insertions(+) diff --git a/backend/baton/src/main/java/touch/baton/domain/member/command/Supporter.java b/backend/baton/src/main/java/touch/baton/domain/member/command/Supporter.java index dc2473e77..7f4bf8eef 100644 --- a/backend/baton/src/main/java/touch/baton/domain/member/command/Supporter.java +++ b/backend/baton/src/main/java/touch/baton/domain/member/command/Supporter.java @@ -120,6 +120,10 @@ public void updateCompany(final Company company) { this.member.updateCompany(company); } + public void increaseReviewCount() { + this.reviewCount.increase(); + } + @Override public boolean equals(final Object o) { if (this == o) return true; diff --git a/backend/baton/src/main/java/touch/baton/domain/member/command/vo/ReviewCount.java b/backend/baton/src/main/java/touch/baton/domain/member/command/vo/ReviewCount.java index 958b89132..92cb239ba 100644 --- a/backend/baton/src/main/java/touch/baton/domain/member/command/vo/ReviewCount.java +++ b/backend/baton/src/main/java/touch/baton/domain/member/command/vo/ReviewCount.java @@ -24,4 +24,8 @@ public class ReviewCount { public ReviewCount(final int value) { this.value = value; } + + public void increase() { + this.value += 1; + } } diff --git a/backend/baton/src/main/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandService.java b/backend/baton/src/main/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandService.java index 6d6d2a292..c76673f61 100644 --- a/backend/baton/src/main/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandService.java +++ b/backend/baton/src/main/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandService.java @@ -137,6 +137,7 @@ public void updateRunnerPostReviewStatusDone(final Long runnerPostId, final Supp } foundRunnerPost.finishReview(); + supporter.increaseReviewCount(); eventPublisher.publishEvent(new RunnerPostReviewStatusDoneEvent(foundRunnerPost.getId())); } From 45d33da9341869c2e148b79ae4caf8795ffc4028 Mon Sep 17 00:00:00 2001 From: Ethan Date: Sat, 17 Feb 2024 21:59:29 +0900 Subject: [PATCH 2/3] =?UTF-8?q?test:=20reviewCount=20=EC=A6=9D=EA=B0=80?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/command/vo/ReviewCount.java | 2 +- .../domain/member/vo/ReviewCountTest.java | 24 +++++++++++++++++++ .../RunnerPostCommandServiceUpdateTest.java | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 backend/baton/src/test/java/touch/baton/domain/member/vo/ReviewCountTest.java diff --git a/backend/baton/src/main/java/touch/baton/domain/member/command/vo/ReviewCount.java b/backend/baton/src/main/java/touch/baton/domain/member/command/vo/ReviewCount.java index 92cb239ba..eb524477a 100644 --- a/backend/baton/src/main/java/touch/baton/domain/member/command/vo/ReviewCount.java +++ b/backend/baton/src/main/java/touch/baton/domain/member/command/vo/ReviewCount.java @@ -26,6 +26,6 @@ public ReviewCount(final int value) { } public void increase() { - this.value += 1; + value += 1; } } diff --git a/backend/baton/src/test/java/touch/baton/domain/member/vo/ReviewCountTest.java b/backend/baton/src/test/java/touch/baton/domain/member/vo/ReviewCountTest.java new file mode 100644 index 000000000..06ec79a7a --- /dev/null +++ b/backend/baton/src/test/java/touch/baton/domain/member/vo/ReviewCountTest.java @@ -0,0 +1,24 @@ +package touch.baton.domain.member.vo; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import touch.baton.domain.member.command.vo.ReviewCount; + +import static org.assertj.core.api.Assertions.assertThat; + +class ReviewCountTest { + + @DisplayName("increaseCount가 호출 되면 value가 1 증가한다.") + @Test + void increaseCount() { + // given + final int initialValue = 0; + final ReviewCount reviewCount = new ReviewCount(initialValue); + + // when + reviewCount.increase(); + + // then + assertThat(reviewCount.getValue()).isEqualTo(initialValue + 1); + } +} diff --git a/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceUpdateTest.java b/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceUpdateTest.java index 4beaca789..98d699ed7 100644 --- a/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceUpdateTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceUpdateTest.java @@ -7,6 +7,7 @@ import touch.baton.domain.member.command.Member; import touch.baton.domain.member.command.Runner; import touch.baton.domain.member.command.Supporter; +import touch.baton.domain.member.command.vo.ReviewCount; import touch.baton.domain.runnerpost.command.RunnerPost; import touch.baton.domain.runnerpost.command.exception.RunnerPostBusinessException; import touch.baton.domain.runnerpost.command.exception.RunnerPostDomainException; @@ -143,6 +144,7 @@ void updateRunnerPostReviewStatusDone() { // given final IsReviewed isReviewed = IsReviewed.notReviewed(); final RunnerPost targetRunnerPost = runnerPostQueryRepository.save(RunnerPostFixture.createWithSupporter(runner, assignedSupporter, IN_PROGRESS, isReviewed)); + final ReviewCount originalReviewCount = new ReviewCount(assignedSupporter.getReviewCount().getValue()); // when runnerPostCommandService.updateRunnerPostReviewStatusDone(targetRunnerPost.getId(), assignedSupporter); @@ -152,6 +154,7 @@ void updateRunnerPostReviewStatusDone() { assertThat(maybeRunnerPost).isPresent(); final RunnerPost actualRunnerPost = maybeRunnerPost.get(); assertThat(actualRunnerPost.getReviewStatus()).isEqualTo(ReviewStatus.DONE); + assertThat(assignedSupporter.getReviewCount()).isEqualTo(new ReviewCount(originalReviewCount.getValue() + 1)); } @DisplayName("없는 게시글의 상태를 리뷰 완료로 변경할 수 없다.") From 3abcf7f230aae5cf56b8aa9cdb8a7d25c881ec0a Mon Sep 17 00:00:00 2001 From: Ethan Date: Mon, 19 Feb 2024 20:07:32 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=B7=B0=EC=88=98=20?= =?UTF-8?q?=EC=A6=9D=EA=B0=80=20=EB=A1=9C=EC=A7=81=EC=9D=84=20RunnerPost?= =?UTF-8?q?=20=EC=95=88=EC=9C=BC=EB=A1=9C=20=EC=98=AE=EA=B9=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/runnerpost/command/RunnerPost.java | 1 + .../service/RunnerPostCommandService.java | 5 +- .../domain/runnerpost/RunnerPostTest.java | 46 +++++++++++++++++-- .../RunnerPostCommandServiceCreateTest.java | 1 + .../RunnerPostCommandServiceDeleteTest.java | 1 + .../RunnerPostCommandServiceEventTest.java | 1 + .../RunnerPostCommandServiceUpdateTest.java | 1 + ...UpdateApplicantCancelationServiceTest.java | 1 + 8 files changed, 50 insertions(+), 7 deletions(-) diff --git a/backend/baton/src/main/java/touch/baton/domain/runnerpost/command/RunnerPost.java b/backend/baton/src/main/java/touch/baton/domain/runnerpost/command/RunnerPost.java index bc5b983bc..86e2d2721 100644 --- a/backend/baton/src/main/java/touch/baton/domain/runnerpost/command/RunnerPost.java +++ b/backend/baton/src/main/java/touch/baton/domain/runnerpost/command/RunnerPost.java @@ -210,6 +210,7 @@ public void addAllRunnerPostTags(final List postTags) { public void finishReview() { updateReviewStatus(ReviewStatus.DONE); + this.supporter.increaseReviewCount(); } public void finishFeedback() { diff --git a/backend/baton/src/main/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandService.java b/backend/baton/src/main/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandService.java index c76673f61..0a29c58dc 100644 --- a/backend/baton/src/main/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandService.java +++ b/backend/baton/src/main/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandService.java @@ -20,6 +20,7 @@ import touch.baton.domain.runnerpost.command.service.dto.RunnerPostApplicantCreateRequest; import touch.baton.domain.runnerpost.command.service.dto.RunnerPostCreateRequest; import touch.baton.domain.runnerpost.command.service.dto.RunnerPostUpdateRequest; +import touch.baton.domain.runnerpost.query.repository.RunnerPostQueryRepository; import touch.baton.domain.tag.command.RunnerPostTag; import touch.baton.domain.tag.command.Tag; import touch.baton.domain.tag.command.repository.TagCommandRepository; @@ -34,6 +35,7 @@ public class RunnerPostCommandService { private final RunnerPostCommandRepository runnerPostCommandRepository; + private final RunnerPostQueryRepository runnerPostQueryRepository; private final TagCommandRepository tagCommandRepository; private final SupporterCommandRepository supporterCommandRepository; private final SupporterRunnerPostCommandRepository supporterRunnerPostCommandRepository; @@ -125,7 +127,7 @@ public Long createRunnerPostApplicant(final Supporter supporter, } public void updateRunnerPostReviewStatusDone(final Long runnerPostId, final Supporter supporter) { - final RunnerPost foundRunnerPost = runnerPostCommandRepository.findById(runnerPostId) + final RunnerPost foundRunnerPost = runnerPostQueryRepository.joinSupporterByRunnerPostId(runnerPostId) .orElseThrow(() -> new RunnerPostBusinessException("해당 식별자의 러너 게시글이 존재하지 않습니다.")); if (Objects.isNull(foundRunnerPost.getSupporter())) { @@ -137,7 +139,6 @@ public void updateRunnerPostReviewStatusDone(final Long runnerPostId, final Supp } foundRunnerPost.finishReview(); - supporter.increaseReviewCount(); eventPublisher.publishEvent(new RunnerPostReviewStatusDoneEvent(foundRunnerPost.getId())); } diff --git a/backend/baton/src/test/java/touch/baton/domain/runnerpost/RunnerPostTest.java b/backend/baton/src/test/java/touch/baton/domain/runnerpost/RunnerPostTest.java index f92dbdb91..81f02f634 100644 --- a/backend/baton/src/test/java/touch/baton/domain/runnerpost/RunnerPostTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/runnerpost/RunnerPostTest.java @@ -1,5 +1,6 @@ package touch.baton.domain.runnerpost; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -71,11 +72,16 @@ class RunnerPostTest { .runnerTechnicalTags(RunnerTechnicalTagsFixture.create(new ArrayList<>())) .build(); - private final Supporter supporter = Supporter.builder() - .reviewCount(new ReviewCount(10)) - .member(supporterMember) - .supporterTechnicalTags(new SupporterTechnicalTags(new ArrayList<>())) - .build(); + private Supporter supporter; + + @BeforeEach + void setUp() { + supporter = Supporter.builder() + .reviewCount(new ReviewCount(10)) + .member(supporterMember) + .supporterTechnicalTags(new SupporterTechnicalTags(new ArrayList<>())) + .build(); + } @DisplayName("runnerPostTags 전체를 추가할 수 있다.") @Test @@ -584,4 +590,34 @@ void fail_same_to_same(final ReviewStatus reviewStatus) { .isInstanceOf(RunnerPostDomainException.class); } } + + @DisplayName("리뷰완료가 되면 ReviewStatus가 Done으로 바뀌고 리뷰를 작성한 ReviewCount가 1 증가한다.") + @Test + void finishReview() { + // given + final ReviewCount originReviewCount = new ReviewCount(supporter.getReviewCount().getValue()); + final RunnerPost runnerPost = RunnerPost.builder() + .title(new Title("러너가 작성하는 리뷰 요청 게시글의 테스트 제목입니다.")) + .implementedContents(new ImplementedContents("안녕하세요. 테스트 내용입니다.")) + .curiousContents(new CuriousContents("궁금한 점입니다.")) + .postscriptContents(new PostscriptContents("잘 부탁드립니다.")) + .pullRequestUrl(new PullRequestUrl("https://github.com")) + .deadline(new Deadline(LocalDateTime.now().plusHours(100))) + .watchedCount(new WatchedCount(0)) + .reviewStatus(ReviewStatus.IN_PROGRESS) + .isReviewed(IsReviewed.notReviewed()) + .runner(runner) + .supporter(supporter) + .runnerPostTags(new RunnerPostTags(new ArrayList<>())) + .build(); + + // when + runnerPost.finishReview(); + + // then + assertAll( + () -> assertThat(runnerPost.getReviewStatus()).isEqualTo(ReviewStatus.DONE), + () -> assertThat(supporter.getReviewCount()).isEqualTo(new ReviewCount(originReviewCount.getValue() + 1)) + ); + } } diff --git a/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceCreateTest.java b/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceCreateTest.java index e069c2963..84d510b4e 100644 --- a/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceCreateTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceCreateTest.java @@ -52,6 +52,7 @@ class RunnerPostCommandServiceCreateTest extends ServiceTestConfig { void setUp() { runnerPostCommandService = new RunnerPostCommandService( runnerPostCommandRepository, + runnerPostQueryRepository, tagCommandRepository, supporterCommandRepository, supporterRunnerPostCommandRepository, diff --git a/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceDeleteTest.java b/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceDeleteTest.java index ea25d3e5b..54e574952 100644 --- a/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceDeleteTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceDeleteTest.java @@ -29,6 +29,7 @@ class RunnerPostCommandServiceDeleteTest extends ServiceTestConfig { void setUp() { runnerPostCommandService = new RunnerPostCommandService( runnerPostCommandRepository, + runnerPostQueryRepository, tagCommandRepository, supporterCommandRepository, supporterRunnerPostCommandRepository, diff --git a/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceEventTest.java b/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceEventTest.java index 00042c60b..ae337c208 100644 --- a/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceEventTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceEventTest.java @@ -37,6 +37,7 @@ class RunnerPostCommandServiceEventTest extends ServiceTestConfig { void setUp() { runnerPostCommandService = new RunnerPostCommandService( runnerPostCommandRepository, + runnerPostQueryRepository, tagCommandRepository, supporterCommandRepository, supporterRunnerPostCommandRepository, diff --git a/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceUpdateTest.java b/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceUpdateTest.java index 98d699ed7..083706095 100644 --- a/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceUpdateTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostCommandServiceUpdateTest.java @@ -44,6 +44,7 @@ class RunnerPostCommandServiceUpdateTest extends ServiceTestConfig { void setUp() { runnerPostCommandService = new RunnerPostCommandService( runnerPostCommandRepository, + runnerPostQueryRepository, tagCommandRepository, supporterCommandRepository, supporterRunnerPostCommandRepository, diff --git a/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostUpdateApplicantCancelationServiceTest.java b/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostUpdateApplicantCancelationServiceTest.java index 4d50c0ec3..ca267021b 100644 --- a/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostUpdateApplicantCancelationServiceTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/runnerpost/command/service/RunnerPostUpdateApplicantCancelationServiceTest.java @@ -35,6 +35,7 @@ class RunnerPostUpdateApplicantCancelationServiceTest extends ServiceTestConfig void setUp() { runnerPostCommandService = new RunnerPostCommandService( runnerPostCommandRepository, + runnerPostQueryRepository, tagCommandRepository, supporterCommandRepository, supporterRunnerPostCommandRepository,