Skip to content

Commit

Permalink
docs: 내 프로필 api 문서 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
nayonsoso committed Dec 19, 2024
1 parent cfff7a4 commit 2afa5a2
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 1 deletion.
6 changes: 5 additions & 1 deletion backend/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ include::highlight-answers.adoc[]

== 인증

include::auth.adoc[]
include::auth.adoc[]

== 사용자

include::member.adoc[]
3 changes: 3 additions & 0 deletions backend/src/docs/asciidoc/member.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
==== 내 프로필 정보

operation::my-profile[snippets="curl-request,request-cookies,http-response,response-fields"]
Original file line number Diff line number Diff line change
@@ -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<ProfileResponse> getProfile() {
ProfileResponse response = memberService.getProfile();
return ResponseEntity.ok(response);
}
}
12 changes: 12 additions & 0 deletions backend/src/main/java/reviewme/member/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package reviewme.member.service.dto;

public record ProfileResponse(
String nickname,
String profileImageUrl
) {
}
6 changes: 6 additions & 0 deletions backend/src/test/java/reviewme/api/ApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -51,6 +53,7 @@
TemplateController.class,
SectionController.class,
HighlightController.class,
MemberController.class,
AuthController.class
})
@ExtendWith(RestDocumentationExtension.class)
Expand Down Expand Up @@ -88,6 +91,9 @@ public abstract class ApiTest {
@MockBean
protected HighlightService highlightService;

@MockBean
protected MemberService memberService;

@MockBean
protected AuthService authService;

Expand Down
45 changes: 45 additions & 0 deletions backend/src/test/java/reviewme/api/MemberApiTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 2afa5a2

Please sign in to comment.