From 2afa5a2f465c3fcf672de549567352dacb37f39a Mon Sep 17 00:00:00 2001 From: nayonsoso Date: Fri, 20 Dec 2024 00:36:07 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20=EB=82=B4=20=ED=94=84=EB=A1=9C=ED=95=84?= =?UTF-8?q?=20api=20=EB=AC=B8=EC=84=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/docs/asciidoc/index.adoc | 6 ++- backend/src/docs/asciidoc/member.adoc | 3 ++ .../member/controller/MemberController.java | 21 +++++++++ .../member/service/MemberService.java | 12 +++++ .../member/service/dto/ProfileResponse.java | 7 +++ .../src/test/java/reviewme/api/ApiTest.java | 6 +++ .../test/java/reviewme/api/MemberApiTest.java | 45 +++++++++++++++++++ 7 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 backend/src/docs/asciidoc/member.adoc create mode 100644 backend/src/main/java/reviewme/member/controller/MemberController.java create mode 100644 backend/src/main/java/reviewme/member/service/MemberService.java create mode 100644 backend/src/main/java/reviewme/member/service/dto/ProfileResponse.java create mode 100644 backend/src/test/java/reviewme/api/MemberApiTest.java diff --git a/backend/src/docs/asciidoc/index.adoc b/backend/src/docs/asciidoc/index.adoc index 4fbe165d1..0575b8a24 100644 --- a/backend/src/docs/asciidoc/index.adoc +++ b/backend/src/docs/asciidoc/index.adoc @@ -43,4 +43,8 @@ include::highlight-answers.adoc[] == 인증 -include::auth.adoc[] \ No newline at end of file +include::auth.adoc[] + +== 사용자 + +include::member.adoc[] \ No newline at end of file diff --git a/backend/src/docs/asciidoc/member.adoc b/backend/src/docs/asciidoc/member.adoc new file mode 100644 index 000000000..9a51e2c94 --- /dev/null +++ b/backend/src/docs/asciidoc/member.adoc @@ -0,0 +1,3 @@ +==== 내 프로필 정보 + +operation::my-profile[snippets="curl-request,request-cookies,http-response,response-fields"] \ No newline at end of file diff --git a/backend/src/main/java/reviewme/member/controller/MemberController.java b/backend/src/main/java/reviewme/member/controller/MemberController.java new file mode 100644 index 000000000..9d95885df --- /dev/null +++ b/backend/src/main/java/reviewme/member/controller/MemberController.java @@ -0,0 +1,21 @@ +package reviewme.member.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import reviewme.member.service.MemberService; +import reviewme.member.service.dto.ProfileResponse; + +@RestController +@RequiredArgsConstructor +public class MemberController { + + private final MemberService memberService; + + @GetMapping("/v2/members/profile/mine") + public ResponseEntity getProfile() { + ProfileResponse response = memberService.getProfile(); + return ResponseEntity.ok(response); + } +} diff --git a/backend/src/main/java/reviewme/member/service/MemberService.java b/backend/src/main/java/reviewme/member/service/MemberService.java new file mode 100644 index 000000000..ef828b848 --- /dev/null +++ b/backend/src/main/java/reviewme/member/service/MemberService.java @@ -0,0 +1,12 @@ +package reviewme.member.service; + +import org.springframework.stereotype.Service; +import reviewme.member.service.dto.ProfileResponse; + +@Service +public class MemberService { + + public ProfileResponse getProfile() { + return null; + } +} diff --git a/backend/src/main/java/reviewme/member/service/dto/ProfileResponse.java b/backend/src/main/java/reviewme/member/service/dto/ProfileResponse.java new file mode 100644 index 000000000..5ec6900cd --- /dev/null +++ b/backend/src/main/java/reviewme/member/service/dto/ProfileResponse.java @@ -0,0 +1,7 @@ +package reviewme.member.service.dto; + +public record ProfileResponse( + String nickname, + String profileImageUrl +) { +} diff --git a/backend/src/test/java/reviewme/api/ApiTest.java b/backend/src/test/java/reviewme/api/ApiTest.java index e1f3bac72..a656602bb 100644 --- a/backend/src/test/java/reviewme/api/ApiTest.java +++ b/backend/src/test/java/reviewme/api/ApiTest.java @@ -30,6 +30,8 @@ import reviewme.auth.service.AuthService; import reviewme.highlight.controller.HighlightController; import reviewme.highlight.service.HighlightService; +import reviewme.member.controller.MemberController; +import reviewme.member.service.MemberService; import reviewme.review.controller.ReviewController; import reviewme.review.service.ReviewDetailLookupService; import reviewme.review.service.ReviewGatheredLookupService; @@ -51,6 +53,7 @@ TemplateController.class, SectionController.class, HighlightController.class, + MemberController.class, AuthController.class }) @ExtendWith(RestDocumentationExtension.class) @@ -88,6 +91,9 @@ public abstract class ApiTest { @MockBean protected HighlightService highlightService; + @MockBean + protected MemberService memberService; + @MockBean protected AuthService authService; diff --git a/backend/src/test/java/reviewme/api/MemberApiTest.java b/backend/src/test/java/reviewme/api/MemberApiTest.java new file mode 100644 index 000000000..ab1da50eb --- /dev/null +++ b/backend/src/test/java/reviewme/api/MemberApiTest.java @@ -0,0 +1,45 @@ +package reviewme.api; + +import static org.springframework.restdocs.cookies.CookieDocumentation.cookieWithName; +import static org.springframework.restdocs.cookies.CookieDocumentation.requestCookies; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; + +import org.junit.jupiter.api.Test; +import org.mockito.BDDMockito; +import org.springframework.restdocs.cookies.CookieDescriptor; +import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; +import org.springframework.restdocs.payload.FieldDescriptor; +import reviewme.member.service.dto.ProfileResponse; + +public class MemberApiTest extends ApiTest { + + @Test + void 내_프로필을_불러온다() { + BDDMockito.given(memberService.getProfile()) + .willReturn(new ProfileResponse("donghoony", "https://aru.image")); + + CookieDescriptor[] cookieDescriptors = { + cookieWithName("JSESSIONID").description("세션 ID") + }; + + FieldDescriptor[] responseFieldDescriptors = { + fieldWithPath("nickname").description("닉네임"), + fieldWithPath("profileImageUrl").description("프로필 이미지 URL") + }; + + RestDocumentationResultHandler handler = document( + "my-profile", + requestCookies(cookieDescriptors), + responseFields(responseFieldDescriptors) + ); + + givenWithSpec().log().all() + .cookie("JSESSIONID", "SESSION12345678") + .when().get("/v2/members/profile/mine") + .then().log().all() + .apply(handler) + .statusCode(200); + } +}