Skip to content

Commit

Permalink
MNG-20 docs: docs 파일 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
minsu20 committed May 6, 2024
1 parent d73cf59 commit cd5ac80
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 28 deletions.
17 changes: 17 additions & 0 deletions src/docs/asciidoc/MissionArchiveComment_API.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[[Mission-Comment-API]]
= Mission Comment API

[[Mission-Comment-댓글-생성]]
== Mission Comment 댓글 생성
operation::mission-comment-controller-test/create_mission_comment[snippets='http-request,path-parameters,request-fields,http-response,response-fields']
---

[[Mission-Comment-댓글-삭제]]
== Mission Comment 댓글 삭제
operation::mission-comment-controller-test/delete_mission_comment[snippets='http-request,path-parameters,response-fields']
---

[[MissionArchive-Comment-댓글-전체-조회]]
== Mission Comment 댓글 전체 조회
operation::mission-comment-controller-test/get_board_comment_all[snippets='http-request,path-parameters,http-response,response-fields']
---
2 changes: 2 additions & 0 deletions src/docs/asciidoc/api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ include::Mission-API.adoc[]

include::MissionArchive-API.adoc[]

include::MissionArchiveComment_API.adoc[]

include::MissionBoard-API.adoc[]

include::MissionGatherBoard-API.adoc[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,4 @@ public ResponseEntity<SuccessResponse<GetAllBoardResponse>> getBoardAll(@Authent
return ResponseEntity.ok(SuccessResponse.create(GET_BOARD_ALL_SUCCESS.getMessage(), this.getBoardUseCase.getAllBoard(user.getSocialId(), teamId)));
}

@PostMapping("/test")
public void test() {
Thread thread1 = new Thread(() -> {
this.getBoardUseCase.getBoardDetail("KAKAO@tester01", 1L,1L);
});
Thread thread2 = new Thread(() -> {
this.getBoardUseCase.getBoardDetail("KAKAO@tester01", 1L,1L);
});
thread1.start();
thread2.start();
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.moing.backend.domain.boardComment.presentation;

import com.moing.backend.config.CommonControllerTest;
import com.moing.backend.domain.boardComment.application.dto.request.CreateBoardCommentRequest;
import com.moing.backend.domain.boardComment.application.dto.response.CommentBlocks;
import com.moing.backend.domain.boardComment.application.dto.response.CreateBoardCommentResponse;
import com.moing.backend.domain.boardComment.application.dto.response.GetBoardCommentResponse;
import com.moing.backend.domain.boardComment.application.service.CreateBoardCommentUseCase;
import com.moing.backend.domain.boardComment.application.service.DeleteBoardCommentUseCase;
import com.moing.backend.domain.boardComment.application.service.GetBoardCommentUseCase;
import com.moing.backend.domain.boardComment.presentattion.BoardCommentController;
import com.moing.backend.domain.comment.application.dto.request.CreateCommentRequest;
import com.moing.backend.domain.comment.application.dto.response.CommentBlocks;
import com.moing.backend.domain.comment.application.dto.response.CreateCommentResponse;
import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
Expand Down Expand Up @@ -44,14 +44,14 @@ public void create_board_comment() throws Exception {
//given
Long teamId = 1L;
Long boardId = 1L;
CreateBoardCommentRequest input = CreateBoardCommentRequest.builder()
CreateCommentRequest input = CreateCommentRequest.builder()
.content("게시글 내용")
.build();

String body = objectMapper.writeValueAsString(input);

CreateBoardCommentResponse output = CreateBoardCommentResponse.builder()
.boardCommentId(1L)
CreateCommentResponse output = CreateCommentResponse.builder()
.commentId(1L)
.build();

given(createBoardCommentUseCase.createBoardComment(any(), any(), any(), any())).willReturn(output);
Expand Down Expand Up @@ -83,7 +83,7 @@ public void create_board_comment() throws Exception {
responseFields(
fieldWithPath("isSuccess").description("true"),
fieldWithPath("message").description("댓글을 생성했습니다"),
fieldWithPath("data.boardCommentId").description("생성한 boardCommentId")
fieldWithPath("data.commentId").description("생성한 boardCommentId")
)
)
);
Expand Down Expand Up @@ -135,7 +135,7 @@ public void get_board_comment_all() throws Exception {
Long boardId = 1L;

CommentBlocks commentBlock = CommentBlocks.builder()
.boardCommentId(1L)
.commentId(1L)
.content("댓글 내용")
.writerIsLeader(true)
.writerNickName("작성자 닉네임")
Expand All @@ -148,7 +148,7 @@ public void get_board_comment_all() throws Exception {

commentBlocks.add(commentBlock);

GetBoardCommentResponse output = new GetBoardCommentResponse(commentBlocks);
GetCommentResponse output = new GetCommentResponse(commentBlocks);

given(getBoardCommentUseCase.getBoardCommentAll(any(), any(), any())).willReturn(output);

Expand Down Expand Up @@ -176,7 +176,7 @@ public void get_board_comment_all() throws Exception {
responseFields(
fieldWithPath("isSuccess").description("true"),
fieldWithPath("message").description("댓글 목록을 모두 조회했습니다."),
fieldWithPath("data.commentBlocks[].boardCommentId").description("댓글 아이디"),
fieldWithPath("data.commentBlocks[].commentId").description("댓글 아이디"),
fieldWithPath("data.commentBlocks[].content").description("댓글 내용"),
fieldWithPath("data.commentBlocks[].writerIsLeader").description("작성자 소모임장 여부"),
fieldWithPath("data.commentBlocks[].writerNickName").description("작성자 닉네임"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest {
.heartStatus("[True/False]")
.hearts(1L)
.contents("contents")
.comments(1L)
.build();

given(missionArchiveCreateUseCase.createArchive(any(),any(),any())).willReturn(output);
Expand Down Expand Up @@ -110,8 +111,10 @@ public class MissionArchiveControllerTest extends CommonControllerTest {
fieldWithPath("data.count").description("미션 인증 횟수"),
fieldWithPath("data.hearts").description("미션 인증 좋아요 수"),
fieldWithPath("data.heartStatus").description("미션 인증 좋아요 상태"),
fieldWithPath("data.contents").description("미션 인증 문구")
)
fieldWithPath("data.contents").description("미션 인증 문구"),
fieldWithPath("data.comments").description("미션 댓글 개수")

)
)
)
.andReturn();
Expand Down Expand Up @@ -139,6 +142,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest {
.heartStatus("[True/False]")
.hearts(1L)
.contents("contents")
.comments(1L)
.build();

given(missionArchiveUpdateUseCase.updateArchive(any(),any(),any())).willReturn(output);
Expand Down Expand Up @@ -183,9 +187,10 @@ public class MissionArchiveControllerTest extends CommonControllerTest {
fieldWithPath("data.count").description("미션 인증 횟수"),
fieldWithPath("data.heartStatus").description("미션 인증 좋아요 상태"),
fieldWithPath("data.hearts").description("미션 인증 좋아요 수"),
fieldWithPath("data.contents").description("미션 인증 문구")
fieldWithPath("data.contents").description("미션 인증 문구"),
fieldWithPath("data.comments").description("미션 댓글 개수")

)
)
)
)
.andReturn();
Expand Down Expand Up @@ -248,6 +253,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest {
.heartStatus("[True/False]")
.hearts(1L)
.contents("contents")
.comments(1L)
.build());

MyMissionArchiveRes output = MyMissionArchiveRes.builder()
Expand Down Expand Up @@ -291,7 +297,8 @@ public class MissionArchiveControllerTest extends CommonControllerTest {
fieldWithPath("data.archives[].count").description("미션 인증 횟수"),
fieldWithPath("data.archives[].heartStatus").description("미션 인증 좋아요 상태"),
fieldWithPath("data.archives[].hearts").description("미션 인증 좋아요 수"),
fieldWithPath("data.archives[].contents").description("미션 인증 문구")
fieldWithPath("data.archives[].contents").description("미션 인증 문구"),
fieldWithPath("data.archives[].comments").description("미션 댓글 개수")


)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.moing.backend.domain.missionComment.domain;

import com.moing.backend.domain.missionComment.domain.repository.MissionCommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;

@SpringBootTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ActiveProfiles("dev")
@Transactional
public class MissionRepositoryTest {

@Autowired
MissionCommentRepository missionCommentRepository;
public void create_Mission_Comment(){

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
package com.moing.backend.domain.missionComment.presentation;

import com.moing.backend.config.CommonControllerTest;
import com.moing.backend.domain.comment.application.dto.request.CreateCommentRequest;
import com.moing.backend.domain.comment.application.dto.response.CommentBlocks;
import com.moing.backend.domain.comment.application.dto.response.CreateCommentResponse;
import com.moing.backend.domain.comment.application.dto.response.GetCommentResponse;
import com.moing.backend.domain.missionComment.application.service.CreateMissionCommentUseCase;
import com.moing.backend.domain.missionComment.application.service.DeleteMissionCommentUseCase;
import com.moing.backend.domain.missionComment.application.service.GetMissionCommentUseCase;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
import org.springframework.test.web.servlet.ResultActions;

import java.util.ArrayList;
import java.util.List;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(MissionCommentController.class)
public class MissionCommentControllerTest extends CommonControllerTest {

@MockBean
private CreateMissionCommentUseCase createMissionCommentUseCase;
@MockBean
private DeleteMissionCommentUseCase deleteMissionCommentUseCase;
@MockBean
private GetMissionCommentUseCase getMissionCommentUseCase;

@Test
public void create_mission_comment() throws Exception {

//given
Long teamId = 1L;
Long missionArchiveId = 1L;
CreateCommentRequest input = CreateCommentRequest.builder()
.content("게시글 내용")
.build();

String body = objectMapper.writeValueAsString(input);

CreateCommentResponse output = CreateCommentResponse.builder()
.commentId(1L)
.build();

given(createMissionCommentUseCase.createBoardComment(any(), any(), any(), any())).willReturn(output);


//when
ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders.
post("/api/{teamId}/{missionArchiveId}/mcomment", teamId, missionArchiveId)
.header("Authorization", "Bearer ACCESS_TOKEN")
.contentType(MediaType.APPLICATION_JSON)
.content(body)
);

//then
actions
.andExpect(status().isOk())
.andDo(
restDocs.document(
requestHeaders(
headerWithName("Authorization").description("접근 토큰")
),
pathParameters(
parameterWithName("teamId").description("팀 아이디"),
parameterWithName("missionArchiveId").description("미션 게시물 아이디")
),
requestFields(
fieldWithPath("content").description("댓글 내용")
),
responseFields(
fieldWithPath("isSuccess").description("true"),
fieldWithPath("message").description("댓글을 생성했습니다"),
fieldWithPath("data.commentId").description("생성한 boardCommentId")
)
)
);
}

@Test
public void delete_mission_comment() throws Exception {

//given
Long teamId = 1L;
Long boardId = 1L;
Long missionArchiveId = 1L;


//when
ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders.
delete("/api/{teamId}/{missionArchiveId}/mcomment/{boardCommentId}", teamId, boardId, missionArchiveId)
.header("Authorization", "Bearer ACCESS_TOKEN")
.contentType(MediaType.APPLICATION_JSON)
);

//then
actions
.andExpect(status().isOk())
.andDo(
restDocs.document(
requestHeaders(
headerWithName("Authorization").description("접근 토큰")
),
pathParameters(
parameterWithName("teamId").description("팀 아이디"),
parameterWithName("missionArchiveId").description("미션 게시글 아이디"),
parameterWithName("boardCommentId").description("댓글 아이디")
),
responseFields(
fieldWithPath("isSuccess").description("true"),
fieldWithPath("message").description("댓글을 삭제했습니다")
)
)
);
}


@Test
public void get_board_comment_all() throws Exception {
//given
List<CommentBlocks> commentBlocks = new ArrayList<>();
Long teamId = 1L;
Long boardId = 1L;

CommentBlocks commentBlock = CommentBlocks.builder()
.commentId(1L)
.content("댓글 내용")
.writerIsLeader(true)
.writerNickName("작성자 닉네임")
.writerProfileImage("작성자 프로필 이미지")
.writerIsDeleted(false)
.isWriter(true)
.createdDate("2023/12/05 23:29")
.makerId(1L)
.build();

commentBlocks.add(commentBlock);

GetCommentResponse output = new GetCommentResponse(commentBlocks);

given(getMissionCommentUseCase.getBoardCommentAll(any(), any(), any())).willReturn(output);


//when
ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders.
get("/api/{teamId}/{missionArchiveId}/mcomment", teamId, boardId)
.header("Authorization", "Bearer ACCESS_TOKEN")
.contentType(MediaType.APPLICATION_JSON)
);


//then
actions
.andExpect(status().isOk())
.andDo(
restDocs.document(
requestHeaders(
headerWithName("Authorization").description("접근 토큰")
),
pathParameters(
parameterWithName("teamId").description("팀 아이디"),
parameterWithName("missionArchiveId").description("게시글 아이디")
),
responseFields(
fieldWithPath("isSuccess").description("true"),
fieldWithPath("message").description("댓글 목록을 모두 조회했습니다."),
fieldWithPath("data.commentBlocks[].commentId").description("댓글 아이디"),
fieldWithPath("data.commentBlocks[].content").description("댓글 내용"),
fieldWithPath("data.commentBlocks[].writerIsLeader").description("작성자 소모임장 여부"),
fieldWithPath("data.commentBlocks[].writerNickName").description("작성자 닉네임"),
fieldWithPath("data.commentBlocks[].writerProfileImage").description("작성자 프로필 이미지"),
fieldWithPath("data.commentBlocks[].writerIsDeleted").description("작성자 삭제 여부"),
fieldWithPath("data.commentBlocks[].isWriter").description("댓글 작성자 여부"),
fieldWithPath("data.commentBlocks[].createdDate").description("생성 시간"),
fieldWithPath("data.commentBlocks[].makerId").description("작성자 Id")
)

)
);
}
}

0 comments on commit cd5ac80

Please sign in to comment.