forked from woowacourse-teams/2023-baton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
러너 본인 프로필 조회 기능 구현 (woowacourse-teams#183)
* refactor: runner response 는 runner 패키지로 이동 * feat: runner 프로필 조회 response 생성 * refactor: 바뀐 response 패키지 적용 * test: IntroductionFixture 추가 * test: 인수테스트 추가 * test: 중복된 테스트 제거 * feat: runner 식별자로 runnerPost 조회 쿼리 생성 * feat: runner 식별자로 runnerPost 조회 서비스 로직 구현 * feat: runner 본인 프로필 조회 기능 구현 * refactor: auth 적용 * refactor: restdocs 관련 테스트 주석 처리 * test: runner fixture 에 introduction 추가 * refactor: controller 메소드 이름 변경
- Loading branch information
1 parent
d280fe1
commit a133913
Showing
19 changed files
with
294 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...end/baton/src/main/java/touch/baton/domain/runner/controller/RunnerProfileController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> readMyProfile(@AuthRunnerPrincipal final Runner runner) { | ||
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)); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../src/main/java/touch/baton/domain/runner/controller/response/RunnerMyProfileResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
backend/baton/src/test/java/touch/baton/controller/runner/RunnerAssuredSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/baton/src/test/java/touch/baton/controller/runner/RunnerProfileAssuredReadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
// ))); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...aton/src/test/java/touch/baton/document/profile/runner/read/RunnerProfileReadApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
// } | ||
//} |
Oops, something went wrong.