diff --git a/backend/baton/src/main/java/touch/baton/domain/oauth/controller/OauthController.java b/backend/baton/src/main/java/touch/baton/domain/oauth/controller/OauthController.java index 82211532d..6ebe011e8 100644 --- a/backend/baton/src/main/java/touch/baton/domain/oauth/controller/OauthController.java +++ b/backend/baton/src/main/java/touch/baton/domain/oauth/controller/OauthController.java @@ -38,6 +38,7 @@ public ResponseEntity login(@PathVariable final OauthType oauthType, @RequestParam final String code ) { final String jwtToken = oauthService.login(oauthType, code); + System.out.println(jwtToken); return ResponseEntity.ok() .header(AUTHORIZATION, jwtToken) diff --git a/backend/baton/src/main/java/touch/baton/domain/runner/controller/RunnerProfileController.java b/backend/baton/src/main/java/touch/baton/domain/runner/controller/RunnerProfileController.java new file mode 100644 index 000000000..cbcb7f65c --- /dev/null +++ b/backend/baton/src/main/java/touch/baton/domain/runner/controller/RunnerProfileController.java @@ -0,0 +1,32 @@ +package touch.baton.domain.runner.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import touch.baton.domain.oauth.controller.resolver.AuthRunnerPrincipal; +import touch.baton.domain.runner.Runner; +import touch.baton.domain.runner.controller.response.RunnerMyProfileResponse; +import touch.baton.domain.runner.controller.response.RunnerResponse; +import touch.baton.domain.runnerpost.controller.response.RunnerPostResponse; +import touch.baton.domain.runnerpost.service.RunnerPostService; + +import java.util.List; + +@RequiredArgsConstructor +@RequestMapping("/api/v1/profile/runner") +@RestController +public class RunnerProfileController { + + private final RunnerPostService runnerPostService; + + @GetMapping + public ResponseEntity readMyProfile(@AuthRunnerPrincipal final Runner runner) { + final RunnerResponse.Mine me = RunnerResponse.Mine.from(runner); + final List runnerPosts = runnerPostService.readRunnerPostsByRunnerId(runner.getId()).stream() + .map(RunnerPostResponse.Mine::from) + .toList(); + return ResponseEntity.ok(new RunnerMyProfileResponse(me, runnerPosts)); + } +} diff --git a/backend/baton/src/main/java/touch/baton/domain/runner/controller/response/RunnerMyProfileResponse.java b/backend/baton/src/main/java/touch/baton/domain/runner/controller/response/RunnerMyProfileResponse.java new file mode 100644 index 000000000..3737ef318 --- /dev/null +++ b/backend/baton/src/main/java/touch/baton/domain/runner/controller/response/RunnerMyProfileResponse.java @@ -0,0 +1,10 @@ +package touch.baton.domain.runner.controller.response; + +import touch.baton.domain.runnerpost.controller.response.RunnerPostResponse; + +import java.util.List; + +public record RunnerMyProfileResponse(RunnerResponse.Mine profile, + List runnerPosts +) { +} diff --git a/backend/baton/src/main/java/touch/baton/domain/runnerpost/controller/response/RunnerProfileResponse.java b/backend/baton/src/main/java/touch/baton/domain/runner/controller/response/RunnerResponse.java similarity index 58% rename from backend/baton/src/main/java/touch/baton/domain/runnerpost/controller/response/RunnerProfileResponse.java rename to backend/baton/src/main/java/touch/baton/domain/runner/controller/response/RunnerResponse.java index e41dff18d..701b29dee 100644 --- a/backend/baton/src/main/java/touch/baton/domain/runnerpost/controller/response/RunnerProfileResponse.java +++ b/backend/baton/src/main/java/touch/baton/domain/runner/controller/response/RunnerResponse.java @@ -1,8 +1,8 @@ -package touch.baton.domain.runnerpost.controller.response; +package touch.baton.domain.runner.controller.response; import touch.baton.domain.runner.Runner; -public record RunnerProfileResponse() { +public record RunnerResponse() { public record Detail(Long runnerId, String name, @@ -29,4 +29,20 @@ public static Simple from(final Runner runner) { ); } } + + public record Mine(String name, + String imageUrl, + String githubUrl, + String introduction + ) { + + public static Mine from(final Runner runner) { + return new Mine( + runner.getMember().getMemberName().getValue(), + runner.getMember().getImageUrl().getValue(), + runner.getMember().getGithubUrl().getValue(), + runner.getIntroduction().getValue() + ); + } + } } diff --git a/backend/baton/src/main/java/touch/baton/domain/runnerpost/controller/response/RunnerPostResponse.java b/backend/baton/src/main/java/touch/baton/domain/runnerpost/controller/response/RunnerPostResponse.java index 44190f605..36537a3cb 100644 --- a/backend/baton/src/main/java/touch/baton/domain/runnerpost/controller/response/RunnerPostResponse.java +++ b/backend/baton/src/main/java/touch/baton/domain/runnerpost/controller/response/RunnerPostResponse.java @@ -1,5 +1,6 @@ package touch.baton.domain.runnerpost.controller.response; +import touch.baton.domain.runner.controller.response.RunnerResponse; import touch.baton.domain.runnerpost.RunnerPost; import touch.baton.domain.runnerpost.vo.ReviewStatus; @@ -17,7 +18,7 @@ public record Detail(Long runnerPostId, Integer chattingCount, ReviewStatus reviewStatus, boolean isOwner, - RunnerProfileResponse.Detail runnerProfile, + RunnerResponse.Detail runnerProfile, List tags ) { @@ -32,7 +33,7 @@ public static Detail from(final RunnerPost runnerPost) { runnerPost.getChattingCount().getValue(), runnerPost.getReviewStatus(), true, - RunnerProfileResponse.Detail.from(runnerPost.getRunner()), + RunnerResponse.Detail.from(runnerPost.getRunner()), convertToTags(runnerPost) ); } @@ -47,7 +48,7 @@ public record DetailVersionTest(Long runnerPostId, Integer watchedCount, Integer chattingCount, ReviewStatus reviewStatus, - RunnerProfileResponse.Detail runnerProfile, + RunnerResponse.Detail runnerProfile, SupporterResponseTestVersion.Simple supporterProfile, boolean isOwner, List tags @@ -62,7 +63,7 @@ public static DetailVersionTest fromVersionTest(final RunnerPost runnerPost) { runnerPost.getWatchedCount().getValue(), runnerPost.getChattingCount().getValue(), runnerPost.getReviewStatus(), - RunnerProfileResponse.Detail.from(runnerPost.getRunner()), + RunnerResponse.Detail.from(runnerPost.getRunner()), SupporterResponseTestVersion.Simple.fromTestVersion(runnerPost.getSupporter()), true, convertToTags(runnerPost) @@ -76,7 +77,7 @@ public record Simple(Long runnerPostId, int watchedCount, int chattingCount, String reviewStatus, - RunnerProfileResponse.Simple runnerProfile, + RunnerResponse.Simple runnerProfile, List tags ) { @@ -88,12 +89,30 @@ public static Simple from(final RunnerPost runnerPost) { runnerPost.getWatchedCount().getValue(), runnerPost.getChattingCount().getValue(), runnerPost.getReviewStatus().name(), - RunnerProfileResponse.Simple.from(runnerPost.getRunner()), + RunnerResponse.Simple.from(runnerPost.getRunner()), convertToTags(runnerPost) ); } } + public record Mine(Long runnerPostId, + String title, + LocalDateTime deadline, + List tags, + String reviewStatus + + ) { + public static Mine from(final RunnerPost runnerPost) { + return new Mine( + runnerPost.getId(), + runnerPost.getTitle().getValue(), + runnerPost.getDeadline().getValue(), + convertToTags(runnerPost), + runnerPost.getReviewStatus().name() + ); + } + } + private static List convertToTags(final RunnerPost runnerPost) { return runnerPost.getRunnerPostTags() .getRunnerPostTags() diff --git a/backend/baton/src/main/java/touch/baton/domain/runnerpost/repository/RunnerPostRepository.java b/backend/baton/src/main/java/touch/baton/domain/runnerpost/repository/RunnerPostRepository.java index 6ac0d8f49..dc3ef6cb9 100644 --- a/backend/baton/src/main/java/touch/baton/domain/runnerpost/repository/RunnerPostRepository.java +++ b/backend/baton/src/main/java/touch/baton/domain/runnerpost/repository/RunnerPostRepository.java @@ -5,7 +5,6 @@ import org.springframework.data.repository.query.Param; import touch.baton.domain.common.vo.Title; import touch.baton.domain.runnerpost.RunnerPost; -import touch.baton.domain.tag.RunnerPostTags; import java.util.List; import java.util.Optional; @@ -21,7 +20,7 @@ public interface RunnerPostRepository extends JpaRepository { """) Optional joinMemberByRunnerPostId(@Param("runnerPostId") final Long runnerPostId); - List readByRunnerId(Long runnerId); + List findByRunnerId(Long runnerId); List readBySupporterId(Long supporterId); Optional readByTitle(Title title); } diff --git a/backend/baton/src/main/java/touch/baton/domain/runnerpost/service/RunnerPostService.java b/backend/baton/src/main/java/touch/baton/domain/runnerpost/service/RunnerPostService.java index b78b48fc2..6984598f1 100644 --- a/backend/baton/src/main/java/touch/baton/domain/runnerpost/service/RunnerPostService.java +++ b/backend/baton/src/main/java/touch/baton/domain/runnerpost/service/RunnerPostService.java @@ -197,4 +197,8 @@ public Long updateRunnerPost(final Long runnerPostId, final RunnerPostUpdateRequ public List readAllRunnerPosts() { return runnerPostRepository.findAll(); } + + public List readRunnerPostsByRunnerId(final Long runnerId) { + return runnerPostRepository.findByRunnerId(runnerId); + } } diff --git a/backend/baton/src/test/java/touch/baton/assure/common/AssuredSupport.java b/backend/baton/src/test/java/touch/baton/assure/common/AssuredSupport.java index 9535ea095..ad2996025 100644 --- a/backend/baton/src/test/java/touch/baton/assure/common/AssuredSupport.java +++ b/backend/baton/src/test/java/touch/baton/assure/common/AssuredSupport.java @@ -29,6 +29,16 @@ public static ExtractableResponse get(final String uri, final String p .extract(); } + public static ExtractableResponse get(final String uri, final String accessToken) { + return RestAssured + .given().log().ifValidationFails() + .header("authorization", "Bearer " + accessToken) + .when().log().ifValidationFails() + .get(uri) + .then().log().ifError() + .extract(); + } + public static ExtractableResponse delete(final String uri, final String pathParamName, final Long id) { return RestAssured .given().log().ifValidationFails() diff --git a/backend/baton/src/test/java/touch/baton/assure/feedback/SupporterFeedbackAssuredCreateTest.java b/backend/baton/src/test/java/touch/baton/assure/feedback/SupporterFeedbackAssuredCreateTest.java index 7b2e77d1a..8efd42e2a 100644 --- a/backend/baton/src/test/java/touch/baton/assure/feedback/SupporterFeedbackAssuredCreateTest.java +++ b/backend/baton/src/test/java/touch/baton/assure/feedback/SupporterFeedbackAssuredCreateTest.java @@ -21,6 +21,7 @@ import static org.springframework.http.HttpStatus.CREATED; import static touch.baton.fixture.domain.SupporterFixture.create; import static touch.baton.fixture.vo.DeadlineFixture.deadline; +import static touch.baton.fixture.vo.IntroductionFixture.introduction; import static touch.baton.fixture.vo.ReviewCountFixture.reviewCount; import static touch.baton.fixture.vo.StarCountFixture.starCount; import static touch.baton.fixture.vo.TotalRatingFixture.totalRating; @@ -34,7 +35,7 @@ class SupporterFeedbackAssuredCreateTest extends AssuredTestConfig { void 러너가_서포터_피드백을_등록한다() { // given final Member memberHyena = memberRepository.save(MemberFixture.createHyena()); - final Runner runnerHyena = runnerRepository.save(RunnerFixture.create(totalRating(0), Grade.BARE_FOOT, memberHyena)); + final Runner runnerHyena = runnerRepository.save(RunnerFixture.create(totalRating(0), Grade.BARE_FOOT, introduction("안녕하세요"), memberHyena)); final Member memberEthan = memberRepository.save(MemberFixture.createEthan()); final Supporter supporterEthan = supporterRepository.save(create(reviewCount(0), starCount(0), totalRating(0), Grade.BARE_FOOT, memberEthan, new ArrayList<>())); final RunnerPost runnerPost = runnerPostRepository.save(RunnerPostFixture.create(runnerHyena, supporterEthan, deadline(LocalDateTime.now().plusHours(100)))); diff --git a/backend/baton/src/test/java/touch/baton/assure/runnerpost/RunnerPostAssuredDeleteTest.java b/backend/baton/src/test/java/touch/baton/assure/runnerpost/RunnerPostAssuredDeleteTest.java index e3b044c7d..1f9421161 100644 --- a/backend/baton/src/test/java/touch/baton/assure/runnerpost/RunnerPostAssuredDeleteTest.java +++ b/backend/baton/src/test/java/touch/baton/assure/runnerpost/RunnerPostAssuredDeleteTest.java @@ -19,6 +19,7 @@ import static touch.baton.fixture.vo.ChattingCountFixture.chattingCount; import static touch.baton.fixture.vo.ContentsFixture.contents; import static touch.baton.fixture.vo.DeadlineFixture.deadline; +import static touch.baton.fixture.vo.IntroductionFixture.introduction; import static touch.baton.fixture.vo.PullRequestUrlFixture.pullRequestUrl; import static touch.baton.fixture.vo.TitleFixture.title; import static touch.baton.fixture.vo.TotalRatingFixture.totalRating; @@ -31,7 +32,7 @@ class RunnerPostAssuredDeleteTest extends AssuredTestConfig { final Member member = MemberFixture.createHyena(); memberRepository.save(member); - final Runner runner = RunnerFixture.create(totalRating(0), Grade.BARE_FOOT, member); + final Runner runner = RunnerFixture.create(totalRating(0), Grade.BARE_FOOT, introduction("hello"), member); runnerRepository.save(runner); final RunnerPost runnerPost = RunnerPostFixture.create(title("제 코드를 리뷰해주세요"), diff --git a/backend/baton/src/test/java/touch/baton/assure/runnerpost/RunnerPostAssuredReadTest.java b/backend/baton/src/test/java/touch/baton/assure/runnerpost/RunnerPostAssuredReadTest.java index fb70c1b01..b9554df3f 100644 --- a/backend/baton/src/test/java/touch/baton/assure/runnerpost/RunnerPostAssuredReadTest.java +++ b/backend/baton/src/test/java/touch/baton/assure/runnerpost/RunnerPostAssuredReadTest.java @@ -5,9 +5,9 @@ import touch.baton.domain.common.vo.Grade; 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.controller.response.RunnerProfileResponse; import touch.baton.domain.runnerpost.vo.ReviewStatus; import touch.baton.fixture.domain.MemberFixture; import touch.baton.fixture.domain.RunnerFixture; @@ -18,6 +18,7 @@ import static touch.baton.fixture.vo.ChattingCountFixture.chattingCount; import static touch.baton.fixture.vo.DeadlineFixture.deadline; +import static touch.baton.fixture.vo.IntroductionFixture.introduction; import static touch.baton.fixture.vo.TotalRatingFixture.totalRating; import static touch.baton.fixture.vo.WatchedCountFixture.watchedCount; @@ -27,7 +28,7 @@ class RunnerPostAssuredReadTest extends AssuredTestConfig { @Test void 러너의_게시글_식별자값으로_러너_게시글_상세_정보_조회에_성공한다() { final Member memberHyena = memberRepository.save(MemberFixture.createHyena()); - final Runner runnerHyena = runnerRepository.save(RunnerFixture.create(totalRating(0), Grade.BARE_FOOT, memberHyena)); + final Runner runnerHyena = runnerRepository.save(RunnerFixture.create(totalRating(0), Grade.BARE_FOOT, introduction("안녕하세요"), memberHyena)); final RunnerPost runnerPost = runnerPostRepository.save(RunnerPostFixture.create(runnerHyena, deadline(LocalDateTime.now().plusHours(100)))); RunnerPostAssuredSupport @@ -42,7 +43,7 @@ class RunnerPostAssuredReadTest extends AssuredTestConfig { chattingCount(0).getValue(), ReviewStatus.NOT_STARTED, true, - RunnerProfileResponse.Detail.from(runnerHyena), + RunnerResponse.Detail.from(runnerHyena), Collections.emptyList() )); } diff --git a/backend/baton/src/test/java/touch/baton/controller/runner/RunnerAssuredSupport.java b/backend/baton/src/test/java/touch/baton/controller/runner/RunnerAssuredSupport.java new file mode 100644 index 000000000..b65502b1b --- /dev/null +++ b/backend/baton/src/test/java/touch/baton/controller/runner/RunnerAssuredSupport.java @@ -0,0 +1,60 @@ +package touch.baton.controller.runner; + +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; +import touch.baton.assure.common.AssuredSupport; +import touch.baton.domain.runner.controller.response.RunnerMyProfileResponse; + +import static org.assertj.core.api.SoftAssertions.assertSoftly; + +@SuppressWarnings("NonAsciiCharacters") +public class RunnerAssuredSupport { + + private RunnerAssuredSupport() { + } + + public static RunnerClientRequestBuilder 클라이언트_요청() { + return new RunnerClientRequestBuilder(); + } + + public static class RunnerClientRequestBuilder { + + private ExtractableResponse response; + + public RunnerClientRequestBuilder 러너_액세스_토큰으로_러너_프로필을_조회한다(final String 러너_액세스_토큰) { + response = AssuredSupport.get("/api/v1/profile/runner", 러너_액세스_토큰); + return this; + } + + public RunnerServerResponseBuilder 서버_응답() { + return new RunnerServerResponseBuilder(response); + } + } + + public static class RunnerServerResponseBuilder { + + private final ExtractableResponse response; + + public RunnerServerResponseBuilder(final ExtractableResponse response) { + this.response = response; + } + + public void 러너_본인_프로필_조회_성공을_검증한다(final RunnerMyProfileResponse 러너_프로필_응답) { + final RunnerMyProfileResponse actual = this.response.as(RunnerMyProfileResponse.class); + + assertSoftly(softly -> { + softly.assertThat(actual.profile().name()).isEqualTo(러너_프로필_응답.profile().name()); + softly.assertThat(actual.profile().imageUrl()).isEqualTo(러너_프로필_응답.profile().imageUrl()); + softly.assertThat(actual.profile().githubUrl()).isEqualTo(러너_프로필_응답.profile().githubUrl()); + softly.assertThat(actual.profile().introduction()).isEqualTo(러너_프로필_응답.profile().introduction()); + softly.assertThat(actual.runnerPosts().size()).isEqualTo(러너_프로필_응답.runnerPosts().size()); + softly.assertThat(actual.runnerPosts().get(0).runnerPostId()).isEqualTo(러너_프로필_응답.runnerPosts().get(0).runnerPostId()); + softly.assertThat(actual.runnerPosts().get(0).title()).isEqualTo(러너_프로필_응답.runnerPosts().get(0).title()); + softly.assertThat(actual.runnerPosts().get(0).deadline()).isEqualToIgnoringSeconds(러너_프로필_응답.runnerPosts().get(0).deadline()); + softly.assertThat(actual.runnerPosts().get(0).tags()).isEqualTo(러너_프로필_응답.runnerPosts().get(0).tags()); + softly.assertThat(actual.runnerPosts().get(0).reviewStatus()).isEqualTo(러너_프로필_응답.runnerPosts().get(0).reviewStatus()); + } + ); + } + } +} diff --git a/backend/baton/src/test/java/touch/baton/controller/runner/RunnerProfileAssuredReadTest.java b/backend/baton/src/test/java/touch/baton/controller/runner/RunnerProfileAssuredReadTest.java new file mode 100644 index 000000000..8ee34aa3e --- /dev/null +++ b/backend/baton/src/test/java/touch/baton/controller/runner/RunnerProfileAssuredReadTest.java @@ -0,0 +1,24 @@ +package touch.baton.controller.runner; + +import org.junit.jupiter.api.Test; +import touch.baton.config.AssuredTestConfig; + +@SuppressWarnings("NonAsciiCharacters") +public class RunnerProfileAssuredReadTest extends AssuredTestConfig { + + @Test + void 액세스_토큰으로_러너_본인의_정보_조회에_성공한다() { + // TODO: Access Token 으로 바꿔야함 +// final String accessToken = "abc123"; +// final Member memberHyena = memberRepository.save(MemberFixture.createHyena()); +// final Runner runnerHyena = runnerRepository.save(RunnerFixture.create(totalRating(0), Grade.BARE_FOOT, introduction("hello"), memberHyena)); +// final RunnerPost runnerPost = runnerPostRepository.save(RunnerPostFixture.create(runnerHyena, deadline(LocalDateTime.now().plusHours(100)))); +// +// RunnerAssuredSupport +// .클라이언트_요청().러너_액세스_토큰으로_러너_프로필을_조회한다(accessToken) +// .서버_응답().러너_본인_프로필_조회_성공을_검증한다(new RunnerMyProfileResponse( +// RunnerResponse.Mine.from(runnerHyena), +// List.of(RunnerPostResponse.Mine.from(runnerPost) +// ))); + } +} diff --git a/backend/baton/src/test/java/touch/baton/document/profile/runner/read/RunnerProfileReadApiTest.java b/backend/baton/src/test/java/touch/baton/document/profile/runner/read/RunnerProfileReadApiTest.java new file mode 100644 index 000000000..91e347093 --- /dev/null +++ b/backend/baton/src/test/java/touch/baton/document/profile/runner/read/RunnerProfileReadApiTest.java @@ -0,0 +1,24 @@ +package touch.baton.document.profile.runner.read; + +//@WebMvcTest(RunnerProfileController.class) +//public class RunnerProfileReadApiTest extends RestdocsConfig { + +// @MockBean +// private RunnerPostService runnerPostService; + +// @DisplayName("러너 프로필 조회 API") +// @Test +// void read() throws Exception { +// // TODO: 로그인 들어오면 작성하겠삼. +// // given +// final Runner runner = RunnerFixture.createRunner(MemberFixture.createHyena()); +// final Deadline deadline = deadline(LocalDateTime.now().plusHours(100)); +// final Tag javaTag = TagFixture.create(tagName("자바"), tagCount(10)); +// final RunnerPost runnerPost = RunnerPostFixture.create(runner, deadline, List.of(javaTag)); +// final RunnerPost spyRunnerPost = spy(runnerPost); +// +// // when +// +// // then +// } +//} diff --git a/backend/baton/src/test/java/touch/baton/domain/runnerpost/repository/RunnerPostRepositoryReadTest.java b/backend/baton/src/test/java/touch/baton/domain/runnerpost/repository/RunnerPostRepositoryReadTest.java deleted file mode 100644 index 9200626d8..000000000 --- a/backend/baton/src/test/java/touch/baton/domain/runnerpost/repository/RunnerPostRepositoryReadTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package touch.baton.domain.runnerpost.repository; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import touch.baton.config.RepositoryTestConfig; -import touch.baton.domain.common.vo.ChattingCount; -import touch.baton.domain.common.vo.Contents; -import touch.baton.domain.common.vo.Grade; -import touch.baton.domain.common.vo.Title; -import touch.baton.domain.common.vo.TotalRating; -import touch.baton.domain.common.vo.WatchedCount; -import touch.baton.domain.member.Member; -import touch.baton.domain.member.repository.MemberRepository; -import touch.baton.domain.member.vo.Company; -import touch.baton.domain.member.vo.Email; -import touch.baton.domain.member.vo.GithubUrl; -import touch.baton.domain.member.vo.ImageUrl; -import touch.baton.domain.member.vo.MemberName; -import touch.baton.domain.member.vo.OauthId; -import touch.baton.domain.runner.Runner; -import touch.baton.domain.runner.repository.RunnerRepository; -import touch.baton.domain.runnerpost.RunnerPost; -import touch.baton.domain.runnerpost.vo.Deadline; -import touch.baton.domain.runnerpost.vo.PullRequestUrl; -import touch.baton.domain.runnerpost.vo.ReviewStatus; -import touch.baton.domain.tag.RunnerPostTags; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; - -class RunnerPostRepositoryReadTest extends RepositoryTestConfig { - - @Autowired - private MemberRepository memberRepository; - - @Autowired - private RunnerRepository runnerRepository; - - @Autowired - private RunnerPostRepository runnerPostRepository; - - @DisplayName("RunnerPost 식별자값으로 RunnerPost 을 삭제한다.") - @Test - void success_deleteByRunnerPostId() { - // given - final Member member = Member.builder() - .memberName(new MemberName("헤에디주")) - .email(new Email("test@test.co.kr")) - .oauthId(new OauthId("dsigjh98gh230gn2oinv913bcuo23nqovbvu93b12voi3bc31j")) - .githubUrl(new GithubUrl("github.com/hyena0608")) - .company(new Company("우아한형제들")) - .imageUrl(new ImageUrl("홍혁준")) - .build(); - final Member saveMember = memberRepository.saveAndFlush(member); - - final Runner runner = Runner.builder() - .totalRating(new TotalRating(100)) - .grade(Grade.BARE_FOOT) - .member(saveMember) - .build(); - final Runner saveRunner = runnerRepository.saveAndFlush(runner); - - final RunnerPost runnerPost = RunnerPost.builder() - .title(new Title("제 코드 리뷰 좀 해주세요!!")) - .contents(new Contents("제 코드는 클린코드가 맞을까요?")) - .deadline(new Deadline(LocalDateTime.now())) - .pullRequestUrl(new PullRequestUrl("https://")) - .watchedCount(new WatchedCount(1)) - .chattingCount(new ChattingCount(1)) - .runnerPostTags(new RunnerPostTags(new ArrayList<>())) - .reviewStatus(ReviewStatus.NOT_STARTED) - .runner(saveRunner) - .supporter(null) - .build(); - final Long saveRunnerPostId = runnerPostRepository.saveAndFlush(runnerPost).getId(); - - // when - runnerPostRepository.deleteById(saveRunnerPostId); - - final Optional maybeRunnerPost = runnerPostRepository.findById(saveRunnerPostId); - - // then - assertThat(maybeRunnerPost).isNotPresent(); - } -} diff --git a/backend/baton/src/test/java/touch/baton/domain/runnerpost/repository/read/RunnerPostRepositoryReadTest.java b/backend/baton/src/test/java/touch/baton/domain/runnerpost/repository/read/RunnerPostRepositoryReadTest.java index 515559f5d..5ef456ee1 100644 --- a/backend/baton/src/test/java/touch/baton/domain/runnerpost/repository/read/RunnerPostRepositoryReadTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/runnerpost/repository/read/RunnerPostRepositoryReadTest.java @@ -87,4 +87,32 @@ void findRunnerPostTagsById_exist() { // then assertThat(expected).containsExactly(javaRunnerPostTag, springRunnerPostTag); } + + @DisplayName("Runner 식별자로 RunnerPost 목록을 조회한다.") + @Test + void findByRunnerId() { + // given + final Member ditoo = MemberFixture.createDitoo(); + memberRepository.save(ditoo); + final Runner runner = RunnerFixture.createRunner(ditoo); + runnerRepository.save(runner); + + final RunnerPost runnerPost = RunnerPostFixture.create(title("제 코드를 리뷰해주세요"), + contents("제 코드의 내용은 이렇습니다."), + pullRequestUrl("https://"), + deadline(LocalDateTime.now().plusHours(10)), + watchedCount(0), + chattingCount(0), + NOT_STARTED, + runner, + null, + RunnerPostTagsFixture.runnerPostTags(new ArrayList<>())); + runnerPostRepository.save(runnerPost); + + // when + final List expected = runnerPostRepository.findByRunnerId(runner.getId()); + + // then + assertThat(expected).containsExactly(runnerPost); + } } diff --git a/backend/baton/src/test/java/touch/baton/domain/runnerpost/service/RunnerPostServiceReadTest.java b/backend/baton/src/test/java/touch/baton/domain/runnerpost/service/RunnerPostServiceReadTest.java index 016904cca..183ee153f 100644 --- a/backend/baton/src/test/java/touch/baton/domain/runnerpost/service/RunnerPostServiceReadTest.java +++ b/backend/baton/src/test/java/touch/baton/domain/runnerpost/service/RunnerPostServiceReadTest.java @@ -28,6 +28,9 @@ import touch.baton.domain.tag.RunnerPostTags; import touch.baton.domain.tag.Tag; import touch.baton.domain.tag.vo.TagCount; +import touch.baton.fixture.domain.MemberFixture; +import touch.baton.fixture.domain.RunnerFixture; +import touch.baton.fixture.domain.RunnerPostFixture; import java.time.LocalDateTime; import java.util.ArrayList; @@ -35,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.SoftAssertions.assertSoftly; class RunnerPostServiceReadTest extends ServiceTestConfig { @@ -45,7 +49,7 @@ void setUp() { runnerPostService = new RunnerPostService(runnerPostRepository, runnerPostTagRepository, tagRepository, supporterRepository); } - @DisplayName("RunnerPost 식별자값으로 RunnerPost 를 조회한다.") + @DisplayName("RunnerPost 식별자로 RunnerPost 를 조회한다.") @Test void success_findByRunnerPostId() { // given @@ -103,11 +107,32 @@ void success_findByRunnerPostId() { .isEqualTo(runnerPost); } - @DisplayName("RunnerPost 식별자값으로 존재하지 않는 RunnerPost 을 조회할 경우 예외가 발생한다.") + @DisplayName("RunnerPost 식별자로 존재하지 않는 RunnerPost 를 조회할 경우 예외가 발생한다.") @Test void fail_findByRunnerPostId_if_runner_post_is_null() { assertThatThrownBy(() -> runnerPostService.readByRunnerPostId(0L)) .isInstanceOf(RunnerPostBusinessException.class) .hasMessage("RunnerPost 의 식별자값으로 러너 게시글을 조회할 수 없습니다."); } + + @DisplayName("Runner 식별자값으로 RunnerPost 를 조회한다.") + @Test + void success_findByRunnerId() { + // given + final Member ditoo = MemberFixture.createDitoo(); + memberRepository.save(ditoo); + final Runner runner = RunnerFixture.createRunner(ditoo); + runnerRepository.save(runner); + final RunnerPost expected = RunnerPostFixture.create(runner, new Deadline(LocalDateTime.now().plusHours(100))); + runnerPostRepository.save(expected); + + // when + final List actual = runnerPostService.readRunnerPostsByRunnerId(runner.getId()); + + // then + assertSoftly(softly -> { + softly.assertThat(actual).hasSize(1); + softly.assertThat(actual.get(0)).isEqualTo(expected); + }); + } } diff --git a/backend/baton/src/test/java/touch/baton/fixture/domain/RunnerFixture.java b/backend/baton/src/test/java/touch/baton/fixture/domain/RunnerFixture.java index f2a3679fa..5dc6d113c 100644 --- a/backend/baton/src/test/java/touch/baton/fixture/domain/RunnerFixture.java +++ b/backend/baton/src/test/java/touch/baton/fixture/domain/RunnerFixture.java @@ -1,10 +1,12 @@ package touch.baton.fixture.domain; import touch.baton.domain.common.vo.Grade; +import touch.baton.domain.common.vo.Introduction; import touch.baton.domain.common.vo.TotalRating; import touch.baton.domain.member.Member; import touch.baton.domain.runner.Runner; +import static touch.baton.fixture.vo.IntroductionFixture.introduction; import static touch.baton.fixture.vo.TotalRatingFixture.totalRating; public abstract class RunnerFixture { @@ -12,15 +14,20 @@ public abstract class RunnerFixture { private RunnerFixture() { } - public static Runner create(final TotalRating totalRating, final Grade grade, final Member member) { + public static Runner create(final TotalRating totalRating, + final Grade grade, + final Introduction introduction, + final Member member + ) { return Runner.builder() .totalRating(totalRating) .grade(grade) + .introduction(introduction) .member(member) .build(); } public static Runner createRunner(final Member member) { - return create(totalRating(5000), Grade.BARE_FOOT, member); + return create(totalRating(5000), Grade.BARE_FOOT, introduction("안녕하세요."), member); } } diff --git a/backend/baton/src/test/java/touch/baton/fixture/vo/IntroductionFixture.java b/backend/baton/src/test/java/touch/baton/fixture/vo/IntroductionFixture.java new file mode 100644 index 000000000..596bca95d --- /dev/null +++ b/backend/baton/src/test/java/touch/baton/fixture/vo/IntroductionFixture.java @@ -0,0 +1,13 @@ +package touch.baton.fixture.vo; + +import touch.baton.domain.common.vo.Introduction; + +public abstract class IntroductionFixture { + + private IntroductionFixture() { + } + + public static Introduction introduction(final String value) { + return new Introduction(value); + } +}