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

Docs: 멤버 API 문서 수정 #63

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 18 additions & 2 deletions src/docs/asciidoc/member.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
==== 멤버검색
멤버정보를 아이디(ID)를 이용해서 검색할 수 있습니다.

[discrete]
===== curl request
include::{snippets}/get-v1-get-member/curl-request.adoc[]

Expand All @@ -26,4 +25,21 @@ include::{snippets}/get-v1-get-member/response-fields.adoc[]
include::{snippets}/get-v1-get-member/http-request.adoc[]

===== HTTP Response
include::{snippets}/get-v1-get-member/http-response.adoc[]
include::{snippets}/get-v1-get-member/http-response.adoc[]

==== 멤버수정
멤버정보를 수정할 수 있습니다.

===== curl request
include::{snippets}/post-v1-my-update-member/curl-request.adoc[]

===== Path parameters

===== Request parameters
include::{snippets}/post-v1-my-update-member/request-fields.adoc[]

===== HTTP Request
include::{snippets}/post-v1-my-update-member/http-request.adoc[]

===== HTTP Response
include::{snippets}/post-v1-my-update-member/http-response.adoc[]
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dnd.gooding.record.command.domain.service;

import com.dnd.gooding.record.command.application.in.CreateRecordUseCase;
import com.dnd.gooding.record.command.application.in.DeleteRecordUseCase;
import com.dnd.gooding.record.command.application.out.RecordFilePort;
import com.dnd.gooding.record.command.application.out.RecordMemberPort;
import com.dnd.gooding.record.command.domain.*;
Expand All @@ -19,7 +20,7 @@
import org.springframework.web.multipart.MultipartFile;

@Service
public class RecordService implements CreateRecordUseCase {
public class RecordService implements CreateRecordUseCase, DeleteRecordUseCase {

private final RecordRepository recordRepository;
private final RecordMemberPort recordMemberPort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.dnd.gooding.common.model.Token;
import com.dnd.gooding.token.command.application.in.CreateTokenUseCase;
import com.dnd.gooding.token.command.application.in.LogoutTokenUseCase;
import com.dnd.gooding.token.command.domain.RefreshToken;
import com.dnd.gooding.token.command.domain.dto.JwtAuthentication;
import com.dnd.gooding.token.command.domain.dto.JwtAuthenticationToken;
Expand All @@ -14,7 +15,7 @@
import org.springframework.transaction.annotation.Transactional;

@Service
public class TokenService implements CreateTokenUseCase {
public class TokenService implements CreateTokenUseCase, LogoutTokenUseCase {

private final JwtTokenProvider jwtTokenProvider;
private final RefreshTokenRepository refreshTokenRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.dnd.gooding.common.model.Interest;
import java.util.HashSet;
import java.util.Set;
import lombok.Builder;

public class MemberRequest {

Expand All @@ -15,6 +16,7 @@ public class MemberRequest {

public MemberRequest() {}

@Builder
public MemberRequest(
String id, String name, String password, Set<Email> emails, Set<Interest> interests) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dnd.gooding.unit.user.command.application;
package com.dnd.gooding.unit.user.command;

import com.dnd.gooding.user.command.domain.repository.MemberRepository;
import com.dnd.gooding.user.command.domain.service.MemberService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.dnd.gooding.unit.user.fixture;

import com.dnd.gooding.user.ui.dto.request.MemberRequest;

public class MemberRequestFixture {

public static MemberRequest create() {
return MemberRequest.builder()
.id("[email protected]")
.name("haeyong")
.emails(null)
.interests(null)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dnd.gooding.unit.user.query.application;
package com.dnd.gooding.unit.user.query;

import com.dnd.gooding.unit.user.fixture.MemberDataFixture;
import com.dnd.gooding.user.query.application.MemberQueryService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.http.HttpHeaders;
import org.springframework.restdocs.RestDocumentationContextProvider;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
Expand All @@ -41,7 +42,7 @@ void member(RestDocumentationContextProvider contextProvider) throws Exception {
new FieldDescriptor[] {
fieldWithPath("id").type(STRING).description("멤버아이디"),
fieldWithPath("name").type(STRING).description("이름"),
fieldWithPath("emails[].address").type(STRING).description("이메일"),
fieldWithPath("emails[].address").type(STRING).description("이메일").optional(),
fieldWithPath("interests[].interestCode").type(STRING).description("관심사코드"),
fieldWithPath("interests[].interestName").type(STRING).description("관심사이름"),
fieldWithPath("oAuthId").type(STRING).description("소셜로그인일련번호"),
Expand All @@ -51,7 +52,9 @@ void member(RestDocumentationContextProvider contextProvider) throws Exception {
String id = "[email protected]";

MockMvcFactory.getRestDocsMockMvc(contextProvider, HOST_LOCAL, memberController)
.perform(RestDocumentationRequestBuilders.get("/api/v1/member/{id}", id))
.perform(
RestDocumentationRequestBuilders.get("/api/v1/member/{id}", id)
.header(HttpHeaders.AUTHORIZATION, "Bearer gqoqmq;13o41mvcvciqermqe"))
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.dnd.gooding.unit.user.ui;

import static com.dnd.gooding.common.constants.Constant.*;
import static com.dnd.gooding.documenation.DocumentUtils.*;
import static org.springframework.restdocs.payload.JsonFieldType.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.restdocs.RestDocumentationContextProvider;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

import com.dnd.gooding.annotations.RestDocsTest;
import com.dnd.gooding.documenation.MockMvcFactory;
import com.dnd.gooding.token.command.application.in.LogoutTokenUseCase;
import com.dnd.gooding.user.command.application.in.UpdateMemberUseCase;
import com.dnd.gooding.user.query.application.MemberQueryService;
import com.dnd.gooding.user.ui.MyMemberController;

@DisplayName("멤버API 문서화")
@RestDocsTest
class MyMemberControllerDocsTest {

@Mock private MemberQueryService memberQueryService;
@Mock private UpdateMemberUseCase updateMemberUseCase;
@Mock private LogoutTokenUseCase logoutTokenUseCase;
@InjectMocks
private MyMemberController myMemberController;

@BeforeEach
void beforeEach() {
memberQueryService = Mockito.mock(MemberQueryService.class);
updateMemberUseCase = Mockito.mock(UpdateMemberUseCase.class);
logoutTokenUseCase = Mockito.mock(LogoutTokenUseCase.class);
myMemberController = new MyMemberController(memberQueryService, updateMemberUseCase, logoutTokenUseCase);
}

@DisplayName("수정 : 멤버정보 수정")
@Test
void member(RestDocumentationContextProvider contextProvider) throws Exception {

var commandJson = """
{
"id": "[email protected]",
"name": "haeyong",
"password": "123456",
"emails": [{ "address" : "[email protected]" }],
"interests": [{ "interestCode" : "1", "interestName" : "쇼핑"}]
}
""";

var requestFieldDescription = new FieldDescriptor[]{
fieldWithPath("id").type(STRING).description("멤버아이디"),
fieldWithPath("name").type(STRING).description("이름"),
fieldWithPath("password").type(STRING).description("비밀번호").optional(),
fieldWithPath("emails[].address").type(STRING).description("이메일").optional(),
fieldWithPath("interests[].interestCode").type(STRING).description("관심사코드").optional(),
fieldWithPath("interests[].interestName").type(STRING).description("관심사이름").optional()
};

MockMvcFactory.getRestDocsMockMvc(contextProvider, HOST_LOCAL, myMemberController)
.perform(RestDocumentationRequestBuilders.post("/api/v1/my/member")
.header(HttpHeaders.AUTHORIZATION, "Bearer gqoqmq;13o41mvcvciqermqe")
.contentType(MediaType.APPLICATION_JSON)
.content(commandJson)
)
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isNoContent())
//REST Docs 용
.andDo(MockMvcRestDocumentation.document("post-v1-my-update-member",
getDocumentRequest(),
getDocumentResponse(),
requestFields(
requestFieldDescription
)
));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
|===
|필드|타입|필수값|설명|형식

{{#fields}}
|{{path}}
|{{type}}
|{{^optional}}true{{/optional}}
a|{{description}}
a|{{#format}}{{format}}{{/format}}{{^format}}{{/format}}
{{/fields}}
|===
Loading