diff --git a/src/docs/asciidoc/MissionArchiveComment_API.adoc b/src/docs/asciidoc/MissionArchiveComment_API.adoc new file mode 100644 index 00000000..9ec5e7fa --- /dev/null +++ b/src/docs/asciidoc/MissionArchiveComment_API.adoc @@ -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'] +--- \ No newline at end of file diff --git a/src/docs/asciidoc/api.adoc b/src/docs/asciidoc/api.adoc index 41519d3c..0addb28b 100644 --- a/src/docs/asciidoc/api.adoc +++ b/src/docs/asciidoc/api.adoc @@ -22,6 +22,8 @@ include::Mission-API.adoc[] include::MissionArchive-API.adoc[] +include::MissionArchiveComment_API.adoc[] + include::MissionBoard-API.adoc[] include::MissionGatherBoard-API.adoc[] diff --git a/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java b/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java index 8ae0002f..6e0c89c4 100644 --- a/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java +++ b/src/main/java/com/moing/backend/domain/board/presentation/BoardController.java @@ -92,16 +92,4 @@ public ResponseEntity> 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(); - } - } diff --git a/src/test/java/com/moing/backend/domain/boardComment/presentation/BoardCommentControllerTest.java b/src/test/java/com/moing/backend/domain/boardComment/presentation/BoardCommentControllerTest.java index 0b8ea674..0d14b897 100644 --- a/src/test/java/com/moing/backend/domain/boardComment/presentation/BoardCommentControllerTest.java +++ b/src/test/java/com/moing/backend/domain/boardComment/presentation/BoardCommentControllerTest.java @@ -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; @@ -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); @@ -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") ) ) ); @@ -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("작성자 닉네임") @@ -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); @@ -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("작성자 닉네임"), diff --git a/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionArchiveControllerTest.java b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionArchiveControllerTest.java index 14a05e86..7ed677de 100644 --- a/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionArchiveControllerTest.java +++ b/src/test/java/com/moing/backend/domain/missionArchive/representation/MissionArchiveControllerTest.java @@ -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); @@ -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(); @@ -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); @@ -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(); @@ -248,6 +253,7 @@ public class MissionArchiveControllerTest extends CommonControllerTest { .heartStatus("[True/False]") .hearts(1L) .contents("contents") + .comments(1L) .build()); MyMissionArchiveRes output = MyMissionArchiveRes.builder() @@ -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("미션 댓글 개수") ) diff --git a/src/test/java/com/moing/backend/domain/missionComment/domain/MissionRepositoryTest.java b/src/test/java/com/moing/backend/domain/missionComment/domain/MissionRepositoryTest.java new file mode 100644 index 00000000..ee4c9b6c --- /dev/null +++ b/src/test/java/com/moing/backend/domain/missionComment/domain/MissionRepositoryTest.java @@ -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(){ + + } + +} diff --git a/src/test/java/com/moing/backend/domain/missionComment/presentation/MissionCommentControllerTest.java b/src/test/java/com/moing/backend/domain/missionComment/presentation/MissionCommentControllerTest.java new file mode 100644 index 00000000..072bc3eb --- /dev/null +++ b/src/test/java/com/moing/backend/domain/missionComment/presentation/MissionCommentControllerTest.java @@ -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 = 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") + ) + + ) + ); + } +}