Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

러너 본인 프로필 조회 기능 구현 #183

Merged
merged 17 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public ResponseEntity<Void> 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<RunnerMyProfileResponse> read(@AuthRunnerPrincipal final Runner runner) {
Copy link
Member

Choose a reason for hiding this comment

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

readXXX로 해주세요

final RunnerResponse.Mine me = RunnerResponse.Mine.from(runner);
final List<RunnerPostResponse.Mine> runnerPosts = runnerPostService.readRunnerPostsByRunnerId(runner.getId()).stream()
.map(RunnerPostResponse.Mine::from)
.toList();
return ResponseEntity.ok(new RunnerMyProfileResponse(me, runnerPosts));
}
}
Original file line number Diff line number Diff line change
@@ -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<RunnerPostResponse.Mine> runnerPosts
) {
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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()
);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -17,7 +18,7 @@ public record Detail(Long runnerPostId,
Integer chattingCount,
ReviewStatus reviewStatus,
boolean isOwner,
RunnerProfileResponse.Detail runnerProfile,
RunnerResponse.Detail runnerProfile,
List<String> tags
) {

Expand All @@ -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)
);
}
Expand All @@ -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<String> tags
Expand All @@ -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)
Expand All @@ -76,7 +77,7 @@ public record Simple(Long runnerPostId,
int watchedCount,
int chattingCount,
String reviewStatus,
RunnerProfileResponse.Simple runnerProfile,
RunnerResponse.Simple runnerProfile,
List<String> tags
) {

Expand All @@ -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<String> 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<String> convertToTags(final RunnerPost runnerPost) {
return runnerPost.getRunnerPostTags()
.getRunnerPostTags()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +20,7 @@ public interface RunnerPostRepository extends JpaRepository<RunnerPost, Long> {
""")
Optional<RunnerPost> joinMemberByRunnerPostId(@Param("runnerPostId") final Long runnerPostId);

List<RunnerPost> readByRunnerId(Long runnerId);
List<RunnerPost> findByRunnerId(Long runnerId);
List<RunnerPost> readBySupporterId(Long supporterId);
Optional<RunnerPost> readByTitle(Title title);
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,8 @@ public Long updateRunnerPost(final Long runnerPostId, final RunnerPostUpdateRequ
public List<RunnerPost> readAllRunnerPosts() {
return runnerPostRepository.findAll();
}

public List<RunnerPost> readRunnerPostsByRunnerId(final Long runnerId) {
return runnerPostRepository.findByRunnerId(runnerId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ public static ExtractableResponse<Response> get(final String uri, final String p
.extract();
}

public static ExtractableResponse<Response> 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<Response> delete(final String uri, final String pathParamName, final Long id) {
return RestAssured
.given().log().ifValidationFails()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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("제 코드를 리뷰해주세요"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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
Expand All @@ -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()
));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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> 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> response;

public RunnerServerResponseBuilder(final ExtractableResponse<Response> 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());
}
);
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
// )));
}
}
Original file line number Diff line number Diff line change
@@ -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
// }
//}
Loading