From a32eb2f257626677a27a3180ac78d51f8d66d6dd Mon Sep 17 00:00:00 2001 From: myhyun0002 Date: Sun, 5 Feb 2023 13:49:25 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20#78=20forum=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=B3=B8=EC=9D=B8=20forum=20=EA=B0=80=EC=A0=B8=EC=98=A4?= =?UTF-8?q?=EA=B8=B0=20api=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20swagger=20?= =?UTF-8?q?=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 +- .../controller/ForumController.java | 8 + .../controller/NestedCommentController.java | 6 +- .../service/CommentServiceTest.java | 170 +++++++----------- 4 files changed, 74 insertions(+), 114 deletions(-) diff --git a/build.gradle b/build.gradle index 53494be..8d62733 100644 --- a/build.gradle +++ b/build.gradle @@ -111,9 +111,7 @@ dependencies { // m1 mac os에서 dsn server 문제 해결 implementation 'io.netty:netty-resolver-dns-native-macos:4.1.68.Final:osx-aarch_64' - - - + testImplementation('org.junit.jupiter:junit-jupiter:5.9.1') } diff --git a/src/main/java/com/example/umc3_teamproject/controller/ForumController.java b/src/main/java/com/example/umc3_teamproject/controller/ForumController.java index e2f45c6..91bbecf 100644 --- a/src/main/java/com/example/umc3_teamproject/controller/ForumController.java +++ b/src/main/java/com/example/umc3_teamproject/controller/ForumController.java @@ -79,6 +79,14 @@ public ResponseTemplate> getForumByU return forumService.getForumByUserId(user_id); } + @ApiOperation(value = "현재 사용중인 사용자가 만든 모든 forum 조회", notes = "user-id의 사용자가 만든 모든 forum 조회") + @ResponseBody + @GetMapping("/user/me") + public ResponseTemplate> getMyForums() throws ResponseException { + Long user_id = jwtService.getmemberId(); + return forumService.getForumByUserId(user_id); + } + // forum_id로 조회 @ApiOperation(value = "해당 forum-id인 forum 하나 조회",notes = "해당 forum-id인 forum 하나 조회") @ResponseBody diff --git a/src/main/java/com/example/umc3_teamproject/controller/NestedCommentController.java b/src/main/java/com/example/umc3_teamproject/controller/NestedCommentController.java index 8c7bd80..81f61f4 100644 --- a/src/main/java/com/example/umc3_teamproject/controller/NestedCommentController.java +++ b/src/main/java/com/example/umc3_teamproject/controller/NestedCommentController.java @@ -63,19 +63,19 @@ public ResponseTemplate> getAllNestedComment return nestedCommentService.getAllByCommentId(comment_id); } - @ApiOperation(value = "해당 comment-id인 comment 좋아요 수 하나 증가") + @ApiOperation(value = "해당 nested-comment-id인 대댓글 좋아요 수 하나 증가") @PutMapping("/{nested-comment-id}/like/plus") public ResponseTemplate likePlus(@PathVariable("nested-comment-id") Long nested_comment_id) throws ResponseException { return nestedCommentService.likePlus(nested_comment_id); } - @ApiOperation(value = "해당 comment-id인 comment 좋아요 수 하나 감소") + @ApiOperation(value = "해당 nested-comment-id인 대댓글 좋아요 수 하나 감소") @PutMapping("/{nested-comment-id}/like/minus") public ResponseTemplate likeMinus(@PathVariable("nested-comment-id") Long nested_comment_id) throws ResponseException { return nestedCommentService.likeMinus(nested_comment_id); } - @ApiOperation(value = "해당 comment-id인 comment 좋아요 수 조회") + @ApiOperation(value = "해당 nested-comment-id인 대댓글 좋아요 수 조회") @GetMapping("/{nested-comment-id}/like") public ResponseTemplate getNestedCommentLike(@PathVariable("nested-comment-id") Long nested_comment_id) throws ResponseException { return nestedCommentService.getLike(nested_comment_id); diff --git a/src/test/java/com/example/umc3_teamproject/service/CommentServiceTest.java b/src/test/java/com/example/umc3_teamproject/service/CommentServiceTest.java index 7652793..e229d1c 100644 --- a/src/test/java/com/example/umc3_teamproject/service/CommentServiceTest.java +++ b/src/test/java/com/example/umc3_teamproject/service/CommentServiceTest.java @@ -1,108 +1,62 @@ -//package com.example.umc3_teamproject.service; -// -//import com.example.umc3_teamproject.config.resTemplate.ResponsePageTemplate; -//import com.example.umc3_teamproject.config.resTemplate.ResponseTemplate; -//import com.example.umc3_teamproject.domain.Member; -//import com.example.umc3_teamproject.domain.dto.request.CommentRequestDto; -//import com.example.umc3_teamproject.domain.dto.request.ForumRequestDto; -//import com.example.umc3_teamproject.domain.dto.request.ScriptRequestDto; -//import com.example.umc3_teamproject.domain.dto.response.CommentResponseDto; -//import com.example.umc3_teamproject.domain.dto.response.ForumResponseDto; -//import com.example.umc3_teamproject.dto.SignupReq; -//import com.example.umc3_teamproject.repository.MemberRepository; -//import org.junit.Test; -//import org.junit.runner.RunWith; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.data.domain.Pageable; -//import org.springframework.data.domain.Sort; -//import org.springframework.test.context.junit4.SpringRunner; -//import org.springframework.transaction.annotation.Transactional; -//import java.util.List; -// -//@RunWith(SpringRunner.class) -//@SpringBootTest -//@Transactional -//public class CommentServiceTest { -// -// @Autowired -// private MemberRepository memberRepository; -// -// @Autowired -// private ScriptService scriptService; -// -// @Autowired -// private ForumService forumService; -// -// @Autowired -// private CommentService commentService; -// -// @Test -// public void 댓글_페이징_테스트() throws Exception{ -// //given -// Long userId = memberRepository.createUser(new SignupReq("asldkj@gmail.com", "sldkfj", 1, "KIM", "sldkfj")); -// -// ScriptRequestDto.Register register = new ScriptRequestDto.Register(); -// register.setTitle("title"); -// register.setUserId(userId); -// scriptService.writeScript(register); -// -// ResponseTemplate forum = forumService.createForum(userId, new ForumRequestDto.createForumRequest()); -// //when -// -// for(int i = 0 ; i <= 200 ; i++){ -// commentService.createComment(forum.getData().getForumId(), new CommentRequestDto.createCommentRequest(userId,"comment")); -// } -// Pageable pageable = new Pageable() { -// @Override -// public int getPageNumber() { -// return 0; -// } -// -// @Override -// public int getPageSize() { -// return 0; -// } -// -// @Override -// public long getOffset() { -// return 0; -// } -// -// @Override -// public Sort getSort() { -// return null; -// } -// -// @Override -// public Pageable next() { -// return null; -// } -// -// @Override -// public Pageable previousOrFirst() { -// return null; -// } -// -// @Override -// public Pageable first() { -// return null; -// } -// -// @Override -// public Pageable withPage(int pageNumber) { -// return null; -// } -// -// @Override -// public boolean hasPrevious() { -// return false; -// } -// }; -// //then -// ResponsePageTemplate> allByForumId = commentService.getAllByForumId(forum.getData().getForumId(),pageable); -// -// System.out.println(allByForumId.getData().size()); -// } -// -//} +package com.example.umc3_teamproject.service; + +import com.example.umc3_teamproject.config.resTemplate.ResponsePageTemplate; +import com.example.umc3_teamproject.config.resTemplate.ResponseTemplate; +import com.example.umc3_teamproject.domain.Member; +import com.example.umc3_teamproject.domain.dto.request.CommentRequestDto; +import com.example.umc3_teamproject.domain.dto.request.ForumRequestDto; +import com.example.umc3_teamproject.domain.dto.request.ScriptRequestDto; +import com.example.umc3_teamproject.domain.dto.response.CommentResponseDto; +import com.example.umc3_teamproject.domain.dto.response.ForumResponseDto; +import com.example.umc3_teamproject.dto.SignupReq; +import com.example.umc3_teamproject.repository.MemberRepository; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; +import java.util.List; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +public class CommentServiceTest { + + @Autowired + private MemberRepository memberRepository; + + @Autowired + private ScriptService scriptService; + + @Autowired + private ForumService forumService; + + @Autowired + private CommentService commentService; + + @Test + public void 댓글_페이징_테스트() throws Exception{ + //given + Long userId = memberRepository.createMember(new SignupReq("asldkj@gmail.com", "sldkfj", 1, "KIM", "sldkfj")); + + ScriptRequestDto.Register register = new ScriptRequestDto.Register(); + register.setTitle("title"); + register.setMemberId(userId); + scriptService.writeScript(register); + + ResponseTemplate forum = forumService.createForum(userId, new ForumRequestDto.createForumRequest()); + //when + + for(int i = 0 ; i <= 200 ; i++){ + commentService.createComment(forum.getData().getForumId(), new CommentRequestDto.createCommentRequest(userId,"comment")); + } + //then + ResponsePageTemplate> allByForumId = commentService.getAllByForumId(forum.getData().getForumId(),pageable); + + System.out.println(allByForumId.getData().size()); + } + +}