From 0ea3f6a85140c1f93f5d79939aa757b7a15f3478 Mon Sep 17 00:00:00 2001 From: Heo Namjun Date: Mon, 21 Mar 2022 18:28:10 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EB=8C=80=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=EC=95=84=EC=9D=B4=EB=94=94=20=ED=95=B4=EC=89=AC=ED=99=94=20mes?= =?UTF-8?q?sage=20close=20#580?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/domain/comment/dto/ReCommentDTO.java | 2 +- .../like/controller/LikeControllerImpl.java | 3 +- .../com/blind/api/global/utils/HashUtil.java | 6 +- .../contorller/AdminControllerImplTest.java | 181 ++++++++---------- .../v2/controller/PostControllerTest.java | 40 +++- 5 files changed, 122 insertions(+), 110 deletions(-) diff --git a/server/api/src/main/java/com/blind/api/domain/comment/dto/ReCommentDTO.java b/server/api/src/main/java/com/blind/api/domain/comment/dto/ReCommentDTO.java index 3f3b30e..78bcac1 100644 --- a/server/api/src/main/java/com/blind/api/domain/comment/dto/ReCommentDTO.java +++ b/server/api/src/main/java/com/blind/api/domain/comment/dto/ReCommentDTO.java @@ -35,7 +35,7 @@ public static ReCommentDTO from(Comment comment) { .postId(comment.getPost().getId()) .authorId(HashUtil.getHashId(comment.getAuthorId(), comment.getPost().getId())) .rootCommentId(comment.getRootCommentId()) - .targetAuthorId(comment.getTargetAuthorId()) + .targetAuthorId(HashUtil.getHashId(comment.getTargetAuthorId(), comment.getPost().getId())) .content(comment.getContent()) .likeCnt(comment.getLikeCnt()) .isAuthor(comment.getIsAuthor()) diff --git a/server/api/src/main/java/com/blind/api/domain/like/controller/LikeControllerImpl.java b/server/api/src/main/java/com/blind/api/domain/like/controller/LikeControllerImpl.java index cd5ff5c..be8ed2e 100644 --- a/server/api/src/main/java/com/blind/api/domain/like/controller/LikeControllerImpl.java +++ b/server/api/src/main/java/com/blind/api/domain/like/controller/LikeControllerImpl.java @@ -38,6 +38,7 @@ public class LikeControllerImpl implements LikeController { public void postLike(Long postId, HttpServletRequest request){ Post post = postService.findById(postId); User user = tokenService.findUserByAccessToken(HeaderUtil.getAccessToken(request)); + User postUser = userService.findById(post.getAuthorId()); if (likeService.checkPostLike(post, user) == false) { likeService.PostLike(post, user, 0L); postService.updateLike(post.getId(), 1L); @@ -48,7 +49,7 @@ public void postLike(Long postId, HttpServletRequest request){ } /*좋아요 10개 이상이면 핫 게시물 등록*/ if (post.getLikeCnt() >= 9 && post.getHotDateTime() == null) { - notificationService.save(user, post, "post", post.getTitle(), "Hot 게시물 선정"); + notificationService.save(postUser, post, "post", post.getTitle(), "Hot 게시물 선정"); userService.setCheck(userService.findById(post.getAuthorId())); postService.setHot(post); } diff --git a/server/api/src/main/java/com/blind/api/global/utils/HashUtil.java b/server/api/src/main/java/com/blind/api/global/utils/HashUtil.java index 3894e73..9dbd223 100644 --- a/server/api/src/main/java/com/blind/api/global/utils/HashUtil.java +++ b/server/api/src/main/java/com/blind/api/global/utils/HashUtil.java @@ -12,8 +12,10 @@ public class HashUtil { public static Long getHashId(Long Id, Long salt) { -// log.info(); - return Hashing.sipHash24(Id, salt).hashString(Id.toString(), StandardCharsets.UTF_8).asLong(); + Long result = Long.valueOf(Hashing.sipHash24(Id, salt).hashString(Id.toString(), StandardCharsets.UTF_8).asInt()); + if (result < 0) + result = result * -1 + Integer.MAX_VALUE; + return result; } } diff --git a/server/api/src/test/java/com/blind/api/domain/admin/contorller/AdminControllerImplTest.java b/server/api/src/test/java/com/blind/api/domain/admin/contorller/AdminControllerImplTest.java index 5691df9..af33e20 100644 --- a/server/api/src/test/java/com/blind/api/domain/admin/contorller/AdminControllerImplTest.java +++ b/server/api/src/test/java/com/blind/api/domain/admin/contorller/AdminControllerImplTest.java @@ -32,6 +32,8 @@ import javax.transaction.Transactional; +import java.util.HashMap; + import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -146,7 +148,7 @@ void init() { } board = boardRepository.findBoardByName("board").orElseGet(()-> null); if (board == null) - board = boardRepository.save(new Board(user, "board")); + board = boardRepository.save(new Board(user1, "board")); post = postRepository.findById(1L).orElseGet(()-> null); if (post == null) post = postService.save(board, user,"title", "content", false); @@ -159,24 +161,14 @@ void init() { @Transactional @DisplayName("관리자 등록") void setAdmin() throws Exception{ - mockMvc.perform(post("/admin/User") - .param("targetUserId", String.valueOf(user1.getId())) - .header("Authorization", "Bearer access0")) - .andExpect(status().isOk()) - .andDo(document("set-admin")) - ; - } + performPost("/admin/user", "set-admin", "userId", user1.getId().toString()); + } @Test @Transactional @DisplayName("관리자 삭제") void deleteAdmin() throws Exception{ - user1.setRoleType(RoleType.ADMIN); - mockMvc.perform(delete("/admin/User") - .param("targetUserId", String.valueOf(user1.getId())) - .header("Authorization", "Bearer access0")) - .andExpect(status().isOk()) - .andDo(document("delete-admin")); + performDelete("/admin/user", "delete-admin", "userId", user1.getId().toString()); } @Test @@ -185,62 +177,36 @@ void deleteAdmin() throws Exception{ void setManager() throws Exception{ MultiValueMap body = new LinkedMultiValueMap<>(); body.add("boardId", String.valueOf(board.getId())); - body.add("targetUserId", String.valueOf(user1.getId())); - mockMvc.perform(post("/admin/manager") - .params(body) - .header("Authorization", "Bearer access0")) - .andExpect(status().isOk()) - .andDo(document("set-manager")) - ; + body.add("userId", String.valueOf(user1.getId())); + performPostWithParams("/admin/manager", "set-manager", body); } @Test @Transactional @DisplayName("매니저 삭제") void deleteManager() throws Exception{ - boardService.setManager(board, user1); - mockMvc.perform(delete("/admin/manager") - .param("boardId", String.valueOf(board.getId())) - .header("Authorization", "Bearer access0")) - .andExpect(status().isOk()) - .andDo(document("delete-manager")) - ; + performDelete("/admin/manager", "delete-manager", "boardId", String.valueOf(board.getId())); } @Test @Transactional @DisplayName("게시판 삭제") void deleteBoard() throws Exception{ - mockMvc.perform(delete("/admin/delete/board") - .param("boardId", String.valueOf(board.getId())) - .header("Authorization", "Bearer access0")) - .andExpect(status().isOk()) - .andDo(document("delete-board")) - ; + performDelete("/admin/board", "delete-board", "boardId", String.valueOf(board.getId())); } @Test @Transactional @DisplayName("게시글 삭제") void deletePost() throws Exception{ - mockMvc.perform(delete("/admin/delete/post") - .param("postId", String.valueOf(post.getId())) - .header("Authorization", "Bearer access0")) - .andExpect(status().isOk()) - .andDo(document("delete-post")) - ; + performDelete("/admin/post", "delete-post", "postId", post.getId().toString()); } @Test @Transactional @DisplayName("댓글 삭제") void deleteComment() throws Exception { - mockMvc.perform(delete("/admin/delete/comment") - .param("commentId", String.valueOf(comment.getId())) - .header("Authorization", "Bearer access0")) - .andExpect(status().isOk()) - .andDo(document("delete-comment")) - ; + performDelete("/admin/comment", "delete-comment", "commentId", comment.getId().toString()); } @Test @@ -249,11 +215,7 @@ void deleteComment() throws Exception { void findAllManagers() throws Exception{ boardService.save(user2, "something"); boardService.save(user1, "wow"); - mockMvc.perform(get("/admin/manager") - .header("Authorization", "Bearer access0")) - .andExpect(status().isOk()) - .andDo(document("all-board")) - ; + performGet("/admin/manager", "all-manager", " ", " "); } @Test @@ -264,13 +226,7 @@ void unBlockPost_blame() throws Exception{ Post blockedPost = postService.save(board,user,"title", "content", false); blockedPost.setBlameCnt(5L); blockedPost.setIsDel(0); - postService.restorePost(blockedPost); - mockMvc.perform(post("/admin/restore/post") - .param("postId", blockedPost.getId().toString()) - .header("Authorization", "Bearer access0")) - .andExpect(status().isOk()) - .andDo(document("all-board")) - ; + performPost("/admin/restore/post", "unblock-post", "postId", post.getId().toString()); } @Test @@ -279,82 +235,103 @@ void unBlockPost_blame() throws Exception{ void unBlockPost_Admin() throws Exception{ /* 관리자에 의해 삭제 */ Post blockedPost = postService.save(board,user,"title", "content", false); - blockedPost.setIsDel(3); - - postService.restorePost(blockedPost); - mockMvc.perform(post("/admin/restore/post") - .param("postId", blockedPost.getId().toString()) - .header("Authorization", "Bearer access0")) - .andExpect(status().isOk()) - .andDo(document("all-board")) - ; - } - - @Test - void allUsers() { + postService.delete(blockedPost, 3); + Post blockedPost1 = postService.findById(blockedPost.getId()); + performPost("/admin/restore/post", "unblock-post", "postId", blockedPost1.getId().toString()); } @Test - void registerAdmin() { - } - - @Test - void unRegisterAdmin() { + @Transactional + @DisplayName("차단된 게시글 조회") + void blockedPost() throws Exception { + performGet("/admin/blocked/post", "get-blocked-post", " ", " "); } @Test - void registerManager() { + @Transactional + @DisplayName("차단된 댓글 조회") + void blockedComment() throws Exception { + comment.setIsDel(3); + performGet("/admin/blocked/comment", "get-blocked-comment", " ", " "); } @Test - void unRegisterManager() { + @Transactional + @DisplayName("삭제된 게시판 조회") + void deletedBoard() throws Exception{ + Board delBoard = boardService.save(user2, "hi"); + delBoard.setIsDel(3); + performGet("/admin/deleted/board", "get-deleted-board", " ", " "); } @Test - void blockedPost() { - } + @Transactional + @DisplayName("삭제된 게시글 조회") + void deletedPost() throws Exception { + comment.setIsDel(1); + performGet("/admin/deleted/post", "get-deleted-post", " ", " "); - @Test - void blockedComment() { } @Test - void deletedBoard() { - } + @Transactional + @DisplayName("삭제된 댓글 조회") + void deletedComment() throws Exception{ + performGet("/admin/deleted/comment", "get-deleted-comment", " ", " "); - @Test - void deletedPost() { } @Test - void deletedComment() { - } + @Transactional + @DisplayName("신고된 게시글 조회") + void blamedPost() throws Exception{ + postService.addBlameCnt(post.getId()); + performGet("/admin/blamed/post", "get-blamed-post", " ", " "); - @Test - void blamedPost() { } @Test - void blamedComment() { - } + @Transactional + @DisplayName("신고된 댓글 조회") + void blamedComment() throws Exception{ + commentService.addBlameCnt(comment.getId()); + performGet("/admin/blamed/comment", "get-blamed-comment", " ", " "); - @Test - void testDeleteBoard() { } - @Test - void testDeletePost() { + private void performPost(String uri, String docName, String paramName, String param) throws Exception{ + mockMvc.perform(post(uri) + .param(paramName, param) + .header("Authorization", "Bearer access0")) + .andExpect(status().isOk()) + .andDo(document("admin/" + docName)) + ; } - @Test - void testDeleteComment() { + private void performPostWithParams(String uri, String docName, MultiValueMap params) throws Exception{ + mockMvc.perform(post(uri) + .params(params) + .header("Authorization", "Bearer access0")) + .andExpect(status().isOk()) + .andDo(document("admin/" + docName)) + ; } - @Test - void restorePost() { + private void performGet(String uri, String docName, String paramName, String param) throws Exception{ + mockMvc.perform(get(uri) + .param(paramName, param) + .header("Authorization", "Bearer access0")) + .andExpect(status().isOk()) + .andDo(document("admin/" + docName)) + ; } - @Test - void restoreComment() { + private void performDelete(String uri, String docName, String paramName, String param) throws Exception{ + mockMvc.perform(delete(uri) + .param(paramName, param) + .header("Authorization", "Bearer access0")) + .andExpect(status().isOk()) + .andDo(document("admin/" + docName)) + ; } } diff --git a/server/api/src/test/java/com/blind/api/domain/post/v2/controller/PostControllerTest.java b/server/api/src/test/java/com/blind/api/domain/post/v2/controller/PostControllerTest.java index 4d6abf5..5174a0c 100644 --- a/server/api/src/test/java/com/blind/api/domain/post/v2/controller/PostControllerTest.java +++ b/server/api/src/test/java/com/blind/api/domain/post/v2/controller/PostControllerTest.java @@ -255,10 +255,42 @@ void findPostByUserId() throws Exception{ postService.save(board, user, "title", "content", false); postService.save(board, user, "title", "content", false); postService.save(board, user, "title", "content", false); - mockMvc.perform(get("/mypage/post") - .header("Authorization", "Bearer access")) + performGet("/mypage/post", "post-mypage", " ", " "); + } + + private void performPost(String uri, String docName, String paramName, String param) throws Exception{ + mockMvc.perform(post(uri) + .param(paramName, param) + .header("Authorization", "Bearer access0")) .andExpect(status().isOk()) - .andDo(document("post-mypage")) - ; + .andDo(document("admin/" + docName)) + ; + } + + private void performPostWithParams(String uri, String docName, MultiValueMap params) throws Exception{ + mockMvc.perform(post(uri) + .params(params) + .header("Authorization", "Bearer access0")) + .andExpect(status().isOk()) + .andDo(document("admin/" + docName)) + ; + } + + private void performGet(String uri, String docName, String paramName, String param) throws Exception{ + mockMvc.perform(get(uri) + .param(paramName, param) + .header("Authorization", "Bearer access0")) + .andExpect(status().isOk()) + .andDo(document("admin/" + docName)) + ; + } + + private void performDelete(String uri, String docName, String paramName, String param) throws Exception{ + mockMvc.perform(delete(uri) + .param(paramName, param) + .header("Authorization", "Bearer access0")) + .andExpect(status().isOk()) + .andDo(document("admin/" + docName)) + ; } } \ No newline at end of file