Skip to content

Commit

Permalink
러너 게시글 상세 조회 API 리팩터링 (#343)
Browse files Browse the repository at this point in the history
* test: Supporter 가 RunnerPost 에 리뷰 신청하는 인수 테스트 추가

* feat: Supporter, RunnerPost 에 리뷰 요청 서비스 기능 구현

* feat: Supporter, RunnerPost 에 리뷰 요청 컨트롤러 구현

* refactor: RunnerPost Detail 응답 객체 수정

* test: RunnerPost 상세 조회 컨트롤러 테스트 수정

* test: RunnerPost 상세 조회 인수 테스트 수정

* feat: RunnerPost 단건 지원자수 count 레포지터리, 서비스 기능 구현

* refactor: RunnerPost 단건 상세 조회 컨트롤러 수정

* chore: 머지 후 변경 작업

* docs: adoc 정렬 및 index.adoc 추가
  • Loading branch information
hyena0608 authored Aug 14, 2023
1 parent 78a0813 commit 70c0d11
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 156 deletions.
24 changes: 24 additions & 0 deletions backend/baton/src/docs/asciidoc/RunnerPostReadApi.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,27 @@ include::{snippets}/../../build/generated-snippets/runner-post-read-api-test/rea
===== *Http Response Fields*

include::{snippets}/../../build/generated-snippets/runner-post-read-api-test/read-referenced-by-supporter/response-fields.adoc[]

=== *러너 게시글 상세 조회*

==== *러너 게시글 단건 상세 조회 API*

===== *Http Request*

include::{snippets}/../../build/generated-snippets/runner-post-read-api-test/read-by-runner-post-id/http-request.adoc[]

===== *Http Request Headers

include::{snippets}/../../build/generated-snippets/runner-post-read-api-test/read-by-runner-post-id/request-headers.adoc[]

===== *Http Request Path Parameters*

include::{snippets}/../../build/generated-snippets/runner-post-read-api-test/read-by-runner-post-id/path-parameters.adoc[]

===== *Http Response*

include::{snippets}/../../build/generated-snippets/runner-post-read-api-test/read-by-runner-post-id/http-response.adoc[]

===== *Http Response Fields*

include::{snippets}/../../build/generated-snippets/runner-post-read-api-test/read-by-runner-post-id/response-fields.adoc[]
6 changes: 6 additions & 0 deletions backend/baton/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ include::MemberLoginProfileReadApi.adoc[]

== *[ 게시글 ]*

include::RunnerPostCreateReadApi.adoc[]
include::RunnerPostReadApi.adoc[]
include::RunnerPostUpdateApi.adoc[]
include::RunnerPostUpdateApplicantCancelationApi.adoc[]
include::RunnerPostDeleteApi.adoc[]

== *[ 러너 ]*

include::RunnerProfileReadApi.adoc[]
include::RunnerLoginProfileReadApi.adoc[]
include::RunnerProfileUpdateApi.adoc[]

== *[ 서포터 ]*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,12 @@ public ResponseEntity<Void> createRunnerPostApplicant(@AuthSupporterPrincipal fi
public ResponseEntity<RunnerPostResponse.Detail> readByRunnerPostId(@AuthRunnerPrincipal(required = false) final Runner runner,
@PathVariable final Long runnerPostId
) {
final RunnerPost runnerPost = runnerPostService.readByRunnerPostId(runnerPostId);
runnerPostService.increaseWatchedCount(runnerPost);
final RunnerPost foundRunnerPost = runnerPostService.readByRunnerPostId(runnerPostId);
final long applicantCount = runnerPostService.readCountByRunnerPostId(foundRunnerPost.getId());

final RunnerPostResponse.Detail response = RunnerPostResponse.Detail.of(
runnerPost,
runnerPost.getRunner().equals(runner)
);
runnerPostService.increaseWatchedCount(foundRunnerPost);
final RunnerPostResponse.Detail response
= RunnerPostResponse.Detail.of(foundRunnerPost, foundRunnerPost.isNotOwner(runner), applicantCount);

return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@ public record Detail(Long runnerPostId,
String contents,
String pullRequestUrl,
LocalDateTime deadline,
Integer watchedCount,
int watchedCount,
long applicantCount,
ReviewStatus reviewStatus,
boolean isOwner,
RunnerResponse.Detail runnerProfile,
List<String> tags
List<String> tags,
RunnerResponse.Detail runnerProfile
) {

public static Detail of(final RunnerPost runnerPost, final boolean isOwner) {
public static Detail of(final RunnerPost runnerPost, final boolean isOwner, final long applicantCount) {
return new Detail(
runnerPost.getId(),
runnerPost.getTitle().getValue(),
runnerPost.getContents().getValue(),
runnerPost.getPullRequestUrl().getValue(),
runnerPost.getDeadline().getValue(),
runnerPost.getWatchedCount().getValue(),
applicantCount,
runnerPost.getReviewStatus(),
isOwner,
RunnerResponse.Detail.from(runnerPost.getRunner()),
convertToTags(runnerPost)
convertToTags(runnerPost),
RunnerResponse.Detail.from(runnerPost.getRunner())
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ public List<Long> readCountsByRunnerPostIds(final List<Long> runnerPostIds) {
return supporterRunnerPostRepository.countByRunnerPostIdIn(runnerPostIds);
}

public long readCountByRunnerPostId(final Long runnerPostId) {
return supporterRunnerPostRepository.countByRunnerPostId(runnerPostId).orElseGet(() -> 0);
}

@Transactional
public void deleteSupporterRunnerPost(final Supporter supporter, final Long runnerPostId) {
final RunnerPost runnerPost = runnerPostRepository.findById(runnerPostId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import touch.baton.domain.supporter.SupporterRunnerPost;

import java.util.List;
import java.util.Optional;

public interface SupporterRunnerPostRepository extends JpaRepository<SupporterRunnerPost, Long> {

Expand All @@ -17,6 +18,14 @@ having srp.runnerPost.id in (:runnerPostIds)
""")
List<Long> countByRunnerPostIdIn(@Param("runnerPostIds") final List<Long> runnerPostIds);

@Query("""
select count(1)
from SupporterRunnerPost srp
group by srp.runnerPost.id
having srp.runnerPost.id = :runnerPostId
""")
Optional<Integer> countByRunnerPostId(@Param("runnerPostId") final Long runnerPostId);

boolean existsByRunnerPostId(final Long runnerPostId);

void deleteBySupporterIdAndRunnerPostId(final Long supporterId, final Long runnerPostId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RunnerPostAssuredCreateTest extends AssuredTestConfig {
.러너_게시글_생성_성공을_검증한다()
.생성한_러너_게시글의_식별자값을_반환한다();

final RunnerPostResponse.Detail 리뷰가_시작되지_않은_에단의_러너_게시글_Detail_응답 = 러너_게시글_Detail_응답을_생성한다(러너_에단, 러너_게시글_생성_요청, NOT_STARTED, 에단의_러너_게시글_식별자값, 1);
final RunnerPostResponse.Detail 리뷰가_시작되지_않은_에단의_러너_게시글_Detail_응답 = 러너_게시글_Detail_응답을_생성한다(러너_에단, 러너_게시글_생성_요청, NOT_STARTED, 에단의_러너_게시글_식별자값, 1, 0L);
RunnerPostAssuredSupport
.클라이언트_요청()
.토큰으로_로그인한다(에단_로그인_토큰)
Expand Down Expand Up @@ -91,7 +91,8 @@ class RunnerPostAssuredCreateTest extends AssuredTestConfig {
final RunnerPostCreateRequest 러너_게시글_생성_요청,
final ReviewStatus 리뷰_상태,
final Long 러너_게시글_식별자값,
final int 조회수
final int 조회수,
final long 서포터_지원자수
) {
return 러너_게시글_Detail_응답(
러너_게시글_식별자값,
Expand All @@ -100,6 +101,7 @@ class RunnerPostAssuredCreateTest extends AssuredTestConfig {
러너_게시글_생성_요청.pullRequestUrl(),
러너_게시글_생성_요청.deadline(),
조회수,
서포터_지원자수,
리뷰_상태,
true,
러너,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,25 @@ private RunnerPostAssuredSupport() {
final String_리퀘스트,
final LocalDateTime 마감기한,
final int 조회수,
final long 서포터_지원자수,
final ReviewStatus 리뷰_상태,
final boolean 주인_여부,
final Runner 러너,
final List<String> 태그_목록
) {
return new RunnerPostResponse.Detail(러너_게시글_식별자값, 제목, 내용, 풀_리퀘스트, 마감기한, 조회수, 리뷰_상태, 주인_여부, RunnerResponse.Detail.from(러너), 태그_목록);
return new RunnerPostResponse.Detail(
러너_게시글_식별자값,
제목,
내용,
_리퀘스트,
마감기한,
조회수,
서포터_지원자수,
리뷰_상태,
주인_여부,
태그_목록,
RunnerResponse.Detail.from(러너)
);
}

public static PageResponse<RunnerPostResponse.ReferencedBySupporter> 서포터가_리뷰_완료한_러너_게시글_응답(final Pageable 페이징_정보,
Expand Down Expand Up @@ -121,16 +134,18 @@ public RunnerPostServerResponseBuilder(final ExtractableResponse<Response> respo
final RunnerPostResponse.Detail actual = this.response.as(RunnerPostResponse.Detail.class);

assertSoftly(softly -> {
softly.assertThat(actual.runnerPostId()).isEqualTo(러너_게시글_응답.runnerPostId());
softly.assertThat(actual.title()).isEqualTo(러너_게시글_응답.title());
softly.assertThat(actual.contents()).isEqualTo(러너_게시글_응답.contents());
softly.assertThat(actual.tags()).isEqualTo(러너_게시글_응답.tags());
softly.assertThat(actual.deadline()).isEqualToIgnoringSeconds(러너_게시글_응답.deadline());
softly.assertThat(actual.watchedCount()).isEqualTo(러너_게시글_응답.watchedCount());
softly.assertThat(actual.applicantCount()).isEqualTo(러너_게시글_응답.applicantCount());
softly.assertThat(actual.reviewStatus()).isEqualTo(러너_게시글_응답.reviewStatus());
softly.assertThat(actual.tags()).isEqualTo(러너_게시글_응답.tags());
softly.assertThat(actual.runnerProfile().name()).isEqualTo(러너_게시글_응답.runnerProfile().name());
softly.assertThat(actual.runnerProfile().company()).isEqualTo(러너_게시글_응답.runnerProfile().company());
softly.assertThat(actual.runnerProfile().imageUrl()).isEqualTo(러너_게시글_응답.runnerProfile().imageUrl());
softly.assertThat(actual.runnerProfile().runnerId()).isEqualTo(러너_게시글_응답.runnerProfile().runnerId());
softly.assertThat(actual.watchedCount()).isEqualTo(러너_게시글_응답.watchedCount());
softly.assertThat(actual.runnerPostId()).isEqualTo(러너_게시글_응답.runnerPostId());
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
import touch.baton.config.AssuredTestConfig;
import touch.baton.domain.member.Member;
import touch.baton.domain.runner.Runner;
import touch.baton.domain.runner.controller.response.RunnerResponse;
import touch.baton.domain.runnerpost.RunnerPost;
import touch.baton.domain.runnerpost.controller.response.RunnerPostResponse;
import touch.baton.domain.runnerpost.vo.ReviewStatus;
import touch.baton.fixture.domain.MemberFixture;
import touch.baton.fixture.domain.RunnerFixture;
import touch.baton.fixture.domain.RunnerPostFixture;

import java.util.ArrayList;

import static java.time.LocalDateTime.now;
import static touch.baton.assure.runnerpost.RunnerPostAssuredSupport.러너_게시글_Detail_응답;
import static touch.baton.assure.runnerpost.RunnerPostAssuredSupport.클라이언트_요청;
import static touch.baton.fixture.vo.DeadlineFixture.deadline;
import static touch.baton.fixture.vo.IntroductionFixture.introduction;
import static touch.baton.fixture.vo.WatchedCountFixture.watchedCount;

@SuppressWarnings("NonAsciiCharacters")
class RunnerPostReadWithLoginedAssuredTest extends AssuredTestConfig {
Expand All @@ -30,22 +27,37 @@ class RunnerPostReadWithLoginedAssuredTest extends AssuredTestConfig {
final RunnerPost 러너_게시글 = runnerPostRepository.save(RunnerPostFixture.create(러너_헤나, deadline(now().plusHours(100))));
final String 로그인용_토큰 = login(사용자_헤나.getSocialId().getValue());

final RunnerPostResponse.Detail 러너_게시글_detail_응답 = 러너_게시글_Detail_응답을_생성한다(러너_헤나, 러너_게시글, ReviewStatus.NOT_STARTED, 러너_게시글.getId(), 1, 0);

클라이언트_요청()
.토큰으로_로그인한다(로그인용_토큰)
.러너_게시글_식별자값으로_러너_게시글을_조회한다(러너_게시글.getId())

.서버_응답()
.러너_게시글_단건_조회_성공을_검증한다(new RunnerPostResponse.Detail(
러너_게시글.getId(),
러너_게시글.getTitle().getValue(),
러너_게시글.getContents().getValue(),
러너_게시글.getPullRequestUrl().getValue(),
러너_게시글.getDeadline().getValue(),
watchedCount(1).getValue(),
ReviewStatus.NOT_STARTED,
true,
RunnerResponse.Detail.from(러너_헤나),
new ArrayList<>()
));
.러너_게시글_단건_조회_성공을_검증한다(러너_게시글_detail_응답);
}

private RunnerPostResponse.Detail 러너_게시글_Detail_응답을_생성한다(final Runner 로그인한_러너,
final RunnerPost 러너_게시글,
final ReviewStatus 리뷰_상태,
final Long 러너_게시글_식별자값,
final int 조회수,
final int 서포터_지원자수
) {
return 러너_게시글_Detail_응답(
러너_게시글_식별자값,
러너_게시글.getTitle().getValue(),
러너_게시글.getContents().getValue(),
러너_게시글.getPullRequestUrl().getValue(),
러너_게시글.getDeadline().getValue(),
조회수,
서포터_지원자수,
리뷰_상태,
!러너_게시글.isNotOwner(로그인한_러너),
러너_게시글.getRunner(),
러너_게시글.getRunnerPostTags().getRunnerPostTags().stream()
.map(runnerPostTag -> runnerPostTag.getTag().getTagName().getValue())
.toList()
);
}
}
Loading

0 comments on commit 70c0d11

Please sign in to comment.