From 4e169e6f286a28263b0aa0168cfd7f9932af6880 Mon Sep 17 00:00:00 2001 From: in seong Park <123macanic@naver.com> Date: Wed, 6 Nov 2024 22:05:51 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20Comment=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20Entity=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20API=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ler.java => CommentCommandController.java} | 40 +--- .../controller/CommentQueryController.java | 60 ++++++ .../dto/request/CommentRegistRequestDTO.java | 2 +- .../comment/entity/Comment.java | 1 - .../comment/repository/CommentRepository.java | 5 - .../repository/CommentViewRepository.java | 14 ++ .../comment/service/CommentService.java | 29 +-- .../comment/service/CommentViewService.java | 35 ++++ .../devlinkbackend/crud/CommentCRUDTest.java | 172 +++++++++++------- 9 files changed, 234 insertions(+), 124 deletions(-) rename src/main/java/com/mtvs/devlinkbackend/comment/controller/{CommentController.java => CommentCommandController.java} (57%) create mode 100644 src/main/java/com/mtvs/devlinkbackend/comment/controller/CommentQueryController.java create mode 100644 src/main/java/com/mtvs/devlinkbackend/comment/repository/CommentViewRepository.java create mode 100644 src/main/java/com/mtvs/devlinkbackend/comment/service/CommentViewService.java diff --git a/src/main/java/com/mtvs/devlinkbackend/comment/controller/CommentController.java b/src/main/java/com/mtvs/devlinkbackend/comment/controller/CommentCommandController.java similarity index 57% rename from src/main/java/com/mtvs/devlinkbackend/comment/controller/CommentController.java rename to src/main/java/com/mtvs/devlinkbackend/comment/controller/CommentCommandController.java index 4ad1eb9..c37724e 100644 --- a/src/main/java/com/mtvs/devlinkbackend/comment/controller/CommentController.java +++ b/src/main/java/com/mtvs/devlinkbackend/comment/controller/CommentCommandController.java @@ -15,11 +15,11 @@ @RestController @RequestMapping("/api/comment") -public class CommentController { +public class CommentCommandController { private final CommentService commentService; private final JwtUtil jwtUtil; - public CommentController(CommentService commentService, JwtUtil jwtUtil) { + public CommentCommandController(CommentService commentService, JwtUtil jwtUtil) { this.commentService = commentService; this.jwtUtil = jwtUtil; } @@ -31,44 +31,12 @@ public CommentController(CommentService commentService, JwtUtil jwtUtil) { }) @PostMapping public ResponseEntity registComment( - @RequestBody CommentRegistRequestDTO commentRegistRequestDTO, - @RequestHeader(name = "Authorization") String authorizationHeader) throws Exception { + @RequestBody CommentRegistRequestDTO commentRegistRequestDTO) { - String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader); - CommentSingleResponseDTO comment = commentService.registComment(commentRegistRequestDTO, accountId); + CommentSingleResponseDTO comment = commentService.registComment(commentRegistRequestDTO); return ResponseEntity.status(HttpStatus.CREATED).body(comment); } - @Operation(summary = "댓글 조회", description = "ID를 사용하여 댓글을 조회합니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "댓글이 성공적으로 조회되었습니다."), - @ApiResponse(responseCode = "404", description = "해당 댓글을 찾을 수 없습니다.") - }) - @GetMapping("/{commentId}") - public ResponseEntity findCommentByCommentId(@PathVariable Long commentId) { - CommentSingleResponseDTO comment = commentService.findCommentByCommentId(commentId); - return comment != null ? ResponseEntity.ok(comment) : ResponseEntity.notFound().build(); - } - - @Operation(summary = "요청 ID로 댓글 조회", description = "특정 요청에 연관된 모든 댓글을 조회합니다.") - @ApiResponse(responseCode = "200", description = "댓글 목록이 성공적으로 조회되었습니다.") - @GetMapping("/request/{requestId}") - public ResponseEntity findCommentsByRequestId(@PathVariable Long requestId) { - CommentListResponseDTO comments = commentService.findCommentsByProjectId(requestId); - return ResponseEntity.ok(comments); - } - - @Operation(summary = "사용자 ID로 댓글 조회", description = "특정 사용자가 작성한 모든 댓글을 조회합니다.") - @ApiResponse(responseCode = "200", description = "사용자의 댓글 목록이 성공적으로 조회되었습니다.") - @GetMapping("/account") - public ResponseEntity findCommentsByAccountId( - @RequestHeader(name = "Authorization") String authorizationHeader) throws Exception { - - String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader); - CommentListResponseDTO comments = commentService.findCommentsByAccountId(accountId); - return ResponseEntity.ok(comments); - } - @Operation(summary = "댓글 수정", description = "기존 댓글의 내용을 수정합니다.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "댓글이 성공적으로 수정되었습니다."), diff --git a/src/main/java/com/mtvs/devlinkbackend/comment/controller/CommentQueryController.java b/src/main/java/com/mtvs/devlinkbackend/comment/controller/CommentQueryController.java new file mode 100644 index 0000000..0618299 --- /dev/null +++ b/src/main/java/com/mtvs/devlinkbackend/comment/controller/CommentQueryController.java @@ -0,0 +1,60 @@ +package com.mtvs.devlinkbackend.comment.controller; + +import com.mtvs.devlinkbackend.comment.dto.response.CommentListResponseDTO; +import com.mtvs.devlinkbackend.comment.dto.response.CommentSingleResponseDTO; +import com.mtvs.devlinkbackend.comment.service.CommentViewService; +import com.mtvs.devlinkbackend.common.util.JwtUtil; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.Arrays; +import java.util.List; + +@RestController +@RequestMapping("/api/comment") +public class CommentQueryController { + + private final JwtUtil jwtUtil; + private final CommentViewService commentViewService; + + public CommentQueryController(JwtUtil jwtUtil, CommentViewService commentViewService) { + this.jwtUtil = jwtUtil; + this.commentViewService = commentViewService; + } + + @Operation(summary = "댓글 조회", description = "ID를 사용하여 댓글을 조회합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "댓글이 성공적으로 조회되었습니다."), + @ApiResponse(responseCode = "404", description = "해당 댓글을 찾을 수 없습니다.") + }) + @GetMapping("/{commentId}") + public ResponseEntity findCommentByCommentId(@PathVariable Long commentId) { + CommentSingleResponseDTO comment = commentViewService.findCommentByCommentId(commentId); + return comment != null ? ResponseEntity.ok(comment) : ResponseEntity.notFound().build(); + } + + @Operation(summary = "CommentIdList로 댓글 조회", description = "CommentIdList에 포함된 모든 댓글을 조회합니다.") + @ApiResponse(responseCode = "200", description = "댓글 목록이 성공적으로 조회되었습니다.") + @GetMapping("/list") + public ResponseEntity findCommentsByCommentIdList( + @RequestParam("ids") Long[] idList) { + + List commentIdList = Arrays.stream(idList).toList(); + CommentListResponseDTO comments = commentViewService.findCommentsByCommentIdList(commentIdList); + return ResponseEntity.ok(comments); + } + + @Operation(summary = "사용자 ID로 댓글 조회", description = "특정 사용자가 작성한 모든 댓글을 조회합니다.") + @ApiResponse(responseCode = "200", description = "사용자의 댓글 목록이 성공적으로 조회되었습니다.") + @GetMapping("/account") + public ResponseEntity findCommentsByAccountId( + @RequestHeader(name = "Authorization") String authorizationHeader) throws Exception { + + String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader); + CommentListResponseDTO comments = commentViewService.findCommentsByAccountId(accountId); + return ResponseEntity.ok(comments); + } +} diff --git a/src/main/java/com/mtvs/devlinkbackend/comment/dto/request/CommentRegistRequestDTO.java b/src/main/java/com/mtvs/devlinkbackend/comment/dto/request/CommentRegistRequestDTO.java index cafa1cd..e7916ff 100644 --- a/src/main/java/com/mtvs/devlinkbackend/comment/dto/request/CommentRegistRequestDTO.java +++ b/src/main/java/com/mtvs/devlinkbackend/comment/dto/request/CommentRegistRequestDTO.java @@ -7,6 +7,6 @@ @AllArgsConstructor @ToString public class CommentRegistRequestDTO { + private Long userId; private String content; - private Long requestId; } diff --git a/src/main/java/com/mtvs/devlinkbackend/comment/entity/Comment.java b/src/main/java/com/mtvs/devlinkbackend/comment/entity/Comment.java index 71edcda..510f7d1 100644 --- a/src/main/java/com/mtvs/devlinkbackend/comment/entity/Comment.java +++ b/src/main/java/com/mtvs/devlinkbackend/comment/entity/Comment.java @@ -13,7 +13,6 @@ @Entity(name = "Comment") @NoArgsConstructor @Getter -@ToString(exclude = "project") // request 필드를 toString에서 제외 public class Comment { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/mtvs/devlinkbackend/comment/repository/CommentRepository.java b/src/main/java/com/mtvs/devlinkbackend/comment/repository/CommentRepository.java index 393d348..218b572 100644 --- a/src/main/java/com/mtvs/devlinkbackend/comment/repository/CommentRepository.java +++ b/src/main/java/com/mtvs/devlinkbackend/comment/repository/CommentRepository.java @@ -10,9 +10,4 @@ @Repository public interface CommentRepository extends JpaRepository { - List findCommentsByAccountId(String accountId); - List findCommentsByProject_ProjectId(Long requestId); - - @Query("SELECT c FROM Comment c WHERE c.project.projectId = :projectId") - List findCommentIdsByProjectId(@Param("projectId") Long projectId); } diff --git a/src/main/java/com/mtvs/devlinkbackend/comment/repository/CommentViewRepository.java b/src/main/java/com/mtvs/devlinkbackend/comment/repository/CommentViewRepository.java new file mode 100644 index 0000000..918ba9d --- /dev/null +++ b/src/main/java/com/mtvs/devlinkbackend/comment/repository/CommentViewRepository.java @@ -0,0 +1,14 @@ +package com.mtvs.devlinkbackend.comment.repository; + +import com.mtvs.devlinkbackend.comment.entity.Comment; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface CommentViewRepository extends JpaRepository { + List findAllByUserId(Long userId); + + List findByCommentIdIn(List commentIdList); +} diff --git a/src/main/java/com/mtvs/devlinkbackend/comment/service/CommentService.java b/src/main/java/com/mtvs/devlinkbackend/comment/service/CommentService.java index eedbde3..c1385bc 100644 --- a/src/main/java/com/mtvs/devlinkbackend/comment/service/CommentService.java +++ b/src/main/java/com/mtvs/devlinkbackend/comment/service/CommentService.java @@ -8,6 +8,8 @@ import com.mtvs.devlinkbackend.comment.repository.CommentRepository; import com.mtvs.devlinkbackend.project.entity.Project; import com.mtvs.devlinkbackend.project.repository.ProjectRepository; +import com.mtvs.devlinkbackend.user.command.model.entity.User; +import com.mtvs.devlinkbackend.user.query.service.UserViewService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,41 +18,28 @@ @Service public class CommentService { private final CommentRepository commentRepository; - private final ProjectRepository projectRepository; + private final UserViewService userViewService; - public CommentService(CommentRepository commentRepository, ProjectRepository projectRepository) { + public CommentService(CommentRepository commentRepository, UserViewService userViewService) { this.commentRepository = commentRepository; - this.projectRepository = projectRepository; + this.userViewService = userViewService; } @Transactional - public CommentSingleResponseDTO registComment(CommentRegistRequestDTO commentRegistRequestDTO, String accountId) { - Project project = projectRepository.findById(commentRegistRequestDTO.getRequestId()).orElse(null); + public CommentSingleResponseDTO registComment(CommentRegistRequestDTO commentRegistRequestDTO) { return new CommentSingleResponseDTO(commentRepository.save(new Comment( commentRegistRequestDTO.getContent(), - accountId, - project + commentRegistRequestDTO.getUserId() ))); } - public CommentSingleResponseDTO findCommentByCommentId(Long commentId) { - return new CommentSingleResponseDTO(commentRepository.findById(commentId).orElse(null)); - } - - public CommentListResponseDTO findCommentsByProjectId(Long requestId) { - return new CommentListResponseDTO(commentRepository.findCommentsByProject_ProjectId(requestId)); - } - - public CommentListResponseDTO findCommentsByAccountId(String accountId) { - return new CommentListResponseDTO(commentRepository.findCommentsByAccountId(accountId)); - } - @Transactional public CommentSingleResponseDTO updateComment(CommentUpdateRequestDTO commentUpdateRequestDTO, String accountId) { Optional comment = commentRepository.findById(commentUpdateRequestDTO.getCommentId()); + User user = userViewService.findUserByEpicAccountId(accountId); if (comment.isPresent()) { Comment foundComment = comment.get(); - if(foundComment.getAccountId().equals(accountId)) { + if(foundComment.getUserId().equals(user.getUserId())) { foundComment.setContent(commentUpdateRequestDTO.getContent()); return new CommentSingleResponseDTO(foundComment); } diff --git a/src/main/java/com/mtvs/devlinkbackend/comment/service/CommentViewService.java b/src/main/java/com/mtvs/devlinkbackend/comment/service/CommentViewService.java new file mode 100644 index 0000000..a6172c7 --- /dev/null +++ b/src/main/java/com/mtvs/devlinkbackend/comment/service/CommentViewService.java @@ -0,0 +1,35 @@ +package com.mtvs.devlinkbackend.comment.service; + +import com.mtvs.devlinkbackend.comment.dto.response.CommentListResponseDTO; +import com.mtvs.devlinkbackend.comment.dto.response.CommentSingleResponseDTO; +import com.mtvs.devlinkbackend.comment.repository.CommentViewRepository; +import com.mtvs.devlinkbackend.user.command.model.entity.User; +import com.mtvs.devlinkbackend.user.query.service.UserViewService; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class CommentViewService { + + private final CommentViewRepository commentViewRepository; + private final UserViewService userViewService; + + public CommentViewService(CommentViewRepository commentViewRepository, UserViewService userViewService) { + this.commentViewRepository = commentViewRepository; + this.userViewService = userViewService; + } + + public CommentSingleResponseDTO findCommentByCommentId(Long commentId) { + return new CommentSingleResponseDTO(commentViewRepository.findById(commentId).orElse(null)); + } + + public CommentListResponseDTO findCommentsByAccountId(String accountId) { + User user = userViewService.findUserByEpicAccountId(accountId); + return new CommentListResponseDTO(commentViewRepository.findAllByUserId(user.getUserId())); + } + + public CommentListResponseDTO findCommentsByCommentIdList(List commentIdList) { + return new CommentListResponseDTO(commentViewRepository.findByCommentIdIn(commentIdList)); + } +} diff --git a/src/test/java/com/mtvs/devlinkbackend/crud/CommentCRUDTest.java b/src/test/java/com/mtvs/devlinkbackend/crud/CommentCRUDTest.java index 396f738..54171a4 100644 --- a/src/test/java/com/mtvs/devlinkbackend/crud/CommentCRUDTest.java +++ b/src/test/java/com/mtvs/devlinkbackend/crud/CommentCRUDTest.java @@ -2,90 +2,140 @@ import com.mtvs.devlinkbackend.comment.dto.request.CommentRegistRequestDTO; import com.mtvs.devlinkbackend.comment.dto.request.CommentUpdateRequestDTO; +import com.mtvs.devlinkbackend.comment.dto.response.CommentListResponseDTO; +import com.mtvs.devlinkbackend.comment.dto.response.CommentSingleResponseDTO; +import com.mtvs.devlinkbackend.comment.entity.Comment; +import com.mtvs.devlinkbackend.comment.repository.CommentRepository; +import com.mtvs.devlinkbackend.comment.repository.CommentViewRepository; import com.mtvs.devlinkbackend.comment.service.CommentService; -import org.junit.jupiter.api.Assertions; +import com.mtvs.devlinkbackend.comment.service.CommentViewService; +import com.mtvs.devlinkbackend.user.command.model.entity.User; +import com.mtvs.devlinkbackend.user.query.service.UserViewService; import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Order; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; -import java.util.stream.Stream; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.*; @SpringBootTest @Transactional public class CommentCRUDTest { - @Autowired + @Mock + private CommentRepository commentRepository; + + @Mock + private UserViewService userViewService; + + @InjectMocks private CommentService commentService; - private static Stream newComment() { - return Stream.of( - Arguments.of(new CommentRegistRequestDTO("내용0", 1L), "계정0"), - Arguments.of(new CommentRegistRequestDTO("내용00", 2L), "계정00") - ); - } + @InjectMocks + private CommentViewService commentViewService; - private static Stream modifiedComment() { - return Stream.of( - Arguments.of(new CommentUpdateRequestDTO(3L, "내용0"), "계정1"), - Arguments.of(new CommentUpdateRequestDTO(4L, "내용00"), "계정2") - ); - } + @Mock + private CommentViewRepository commentViewRepository; + + @Test + @DisplayName("코멘트를 등록하는 테스트") + void registCommentTest() { + CommentRegistRequestDTO requestDTO = new CommentRegistRequestDTO(1L, "테스트 내용"); + Comment comment = new Comment("테스트 내용", 1L); + + when(commentRepository.save(any(Comment.class))).thenReturn(comment); - @DisplayName("코멘트 추가 테스트") - @ParameterizedTest - @MethodSource("newComment") - @Order(0) - public void testCreateComment(CommentRegistRequestDTO commentRegistRequestDTO, String accountId) { - Assertions.assertDoesNotThrow(() -> commentService.registComment(commentRegistRequestDTO, accountId)); + CommentSingleResponseDTO responseDTO = commentService.registComment(requestDTO); + + assertEquals("테스트 내용", responseDTO.getData().getContent()); + verify(commentRepository, times(1)).save(any(Comment.class)); } - @DisplayName("PK로 코멘트 조회 테스트") - @ValueSource(longs = {1,2}) - @ParameterizedTest - @Order(1) - public void testFindCommentByCommentId(long commentId) { - Assertions.assertDoesNotThrow(() -> - System.out.println("Comment = " + commentService.findCommentByCommentId(commentId))); + @Test + @DisplayName("코멘트를 수정하는 테스트") + void updateCommentTest() { + CommentUpdateRequestDTO requestDTO = new CommentUpdateRequestDTO(1L, "수정된 내용"); + Comment comment = new Comment("기존 내용", 1L); + User user = new User(); + user.setUserId(1L); + + when(commentRepository.findById(anyLong())).thenReturn(Optional.of(comment)); + when(userViewService.findUserByEpicAccountId(anyString())).thenReturn(user); + + CommentSingleResponseDTO responseDTO = commentService.updateComment(requestDTO, "testAccount"); + + assertEquals("수정된 내용", responseDTO.getData().getContent()); + verify(commentRepository, times(1)).findById(anyLong()); } - @DisplayName("계정 ID에 따른 코멘트 조회 테스트") - @ValueSource( strings = {"계정1", "계정2"}) - @ParameterizedTest - @Order(2) - public void testFindCommentsByAccountId(String accountId) { - Assertions.assertDoesNotThrow(() -> - System.out.println("Comment = " + commentService.findCommentsByAccountId(accountId))); + @Test + @DisplayName("코멘트를 삭제하는 테스트") + void deleteCommentTest() { + Long commentId = 1L; + + commentService.deleteComment(commentId); + + verify(commentRepository, times(1)).deleteById(commentId); } - @DisplayName("의뢰 ID에 따른 코멘트 조회 테스트") - @ValueSource( longs = {1,2}) - @ParameterizedTest - @Order(3) - public void testFindCommentsByRequestId(long requestId) { - Assertions.assertDoesNotThrow(() -> - System.out.println("Comment = " + commentService.findCommentsByProjectId(requestId))); + @Test + @DisplayName("코멘트 ID로 코멘트를 조회하는 테스트") + void findCommentByCommentIdTest() { + Long commentId = 1L; + Comment comment = mock(Comment.class); // 모킹된 Comment 객체 사용 + + when(commentViewRepository.findById(commentId)).thenReturn(Optional.of(comment)); + when(comment.getContent()).thenReturn("테스트 내용"); // 모킹된 객체의 메서드를 호출 + + CommentSingleResponseDTO responseDTO = commentViewService.findCommentByCommentId(commentId); + + assertEquals("테스트 내용", responseDTO.getData().getContent()); + verify(commentViewRepository, times(1)).findById(commentId); } - @DisplayName("코멘트 수정 테스트") - @MethodSource("modifiedComment") - @ParameterizedTest - @Order(4) - public void testUpdateComment(CommentUpdateRequestDTO commentUpdateRequestDTO, String accountId) { - Assertions.assertDoesNotThrow(() -> - System.out.println(commentService.updateComment(commentUpdateRequestDTO, accountId))); + @Test + @DisplayName("계정 ID로 코멘트 리스트를 조회하는 테스트") + void findCommentsByAccountIdTest() { + User user = mock(User.class); // 모킹된 User 객체 사용 + when(user.getUserId()).thenReturn(1L); + + Comment comment1 = mock(Comment.class); // 모킹된 Comment 객체 사용 + Comment comment2 = mock(Comment.class); // 모킹된 Comment 객체 사용 + when(comment1.getContent()).thenReturn("테스트 내용1"); + when(comment2.getContent()).thenReturn("테스트 내용2"); + + List comments = Arrays.asList(comment1, comment2); + + when(userViewService.findUserByEpicAccountId(anyString())).thenReturn(user); + when(commentViewRepository.findAllByUserId(1L)).thenReturn(comments); + + CommentListResponseDTO responseDTO = commentViewService.findCommentsByAccountId("testAccount"); + + assertEquals(2, responseDTO.getData().size()); + verify(commentViewRepository, times(1)).findAllByUserId(1L); } - @DisplayName("코멘트 삭제 테스트") - @ValueSource(longs = {0,1}) - @ParameterizedTest - @Order(5) - public void testDeleteRequest(long commentId) { - Assertions.assertDoesNotThrow(() -> - commentService.deleteComment(commentId)); + @Test + @DisplayName("코멘트 ID 리스트로 코멘트를 조회하는 테스트") + void findCommentsByCommentIdListTest() { + List commentIdList = Arrays.asList(1L, 2L); + Comment comment1 = mock(Comment.class); // 모킹된 Comment 객체 사용 + Comment comment2 = mock(Comment.class); // 모킹된 Comment 객체 사용 + + List comments = Arrays.asList(comment1, comment2); + + when(commentViewRepository.findByCommentIdIn(commentIdList)).thenReturn(comments); + + CommentListResponseDTO responseDTO = commentViewService.findCommentsByCommentIdList(commentIdList); + + assertEquals(2, responseDTO.getData().size()); + verify(commentViewRepository, times(1)).findByCommentIdIn(commentIdList); } } From da08a76b8a780880604b59ac504bed9fc36d98a0 Mon Sep 17 00:00:00 2001 From: in seong Park <123macanic@naver.com> Date: Wed, 6 Nov 2024 22:06:48 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix=20:=20=EC=9D=B4=EC=A0=84=EC=9D=98=20Ent?= =?UTF-8?q?ity=EB=A1=9C=20=EB=A7=8C=EB=93=A4=EC=96=B4=EC=A7=84=20JPQL=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/model/entity/Evaluation.java | 2 +- .../project/repository/ProjectRepository.java | 10 ------- .../repository/ProjectViewRepository.java | 27 +++---------------- 3 files changed, 5 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/mtvs/devlinkbackend/evaluation/command/model/entity/Evaluation.java b/src/main/java/com/mtvs/devlinkbackend/evaluation/command/model/entity/Evaluation.java index 80a981e..5f9bd3c 100644 --- a/src/main/java/com/mtvs/devlinkbackend/evaluation/command/model/entity/Evaluation.java +++ b/src/main/java/com/mtvs/devlinkbackend/evaluation/command/model/entity/Evaluation.java @@ -15,7 +15,7 @@ @Entity(name = "Evaluation") @Getter @Setter -@ToString(exclude = "categoryInfo") +@ToString(exclude = "skillCategoryInfo") @NoArgsConstructor public class Evaluation { @Id diff --git a/src/main/java/com/mtvs/devlinkbackend/project/repository/ProjectRepository.java b/src/main/java/com/mtvs/devlinkbackend/project/repository/ProjectRepository.java index e3cd816..8426db6 100644 --- a/src/main/java/com/mtvs/devlinkbackend/project/repository/ProjectRepository.java +++ b/src/main/java/com/mtvs/devlinkbackend/project/repository/ProjectRepository.java @@ -1,19 +1,9 @@ package com.mtvs.devlinkbackend.project.repository; import com.mtvs.devlinkbackend.project.entity.Project; -import com.mtvs.devlinkbackend.project.repository.projection.ProjectIdAndContent; -import com.mtvs.devlinkbackend.project.repository.projection.ProjectSummary; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.List; - @Repository public interface ProjectRepository extends JpaRepository { } diff --git a/src/main/java/com/mtvs/devlinkbackend/project/repository/ProjectViewRepository.java b/src/main/java/com/mtvs/devlinkbackend/project/repository/ProjectViewRepository.java index dfa8e0f..34ccef9 100644 --- a/src/main/java/com/mtvs/devlinkbackend/project/repository/ProjectViewRepository.java +++ b/src/main/java/com/mtvs/devlinkbackend/project/repository/ProjectViewRepository.java @@ -2,19 +2,15 @@ import com.mtvs.devlinkbackend.project.entity.Project; import com.mtvs.devlinkbackend.project.repository.projection.ProjectIdAndContent; -import com.mtvs.devlinkbackend.project.repository.projection.ProjectSummary; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import java.time.LocalDate; -import java.util.List; public interface ProjectViewRepository extends JpaRepository { // AccountId로 프로젝트 조회 (페이징 추가) - Page findProjectsByAccountId(String accountId, Pageable pageable); + Page findProjectsByUserId(Long userId, Pageable pageable); // WorkType으로 프로젝트 조회 (페이징 추가) Page findProjectsByWorkType(String workType, Pageable pageable); @@ -26,24 +22,9 @@ public interface ProjectViewRepository extends JpaRepository { Page findProjectsByTitleContainingIgnoreCase(String title, Pageable pageable); // 시작일과 종료일 기준으로 프로젝트 조회 (페이징 추가) - Page findProjectsByStartDateTimeLessThanEqualOrEndDateTimeGreaterThanEqual( - LocalDate startDateTime, LocalDate endDateTime, Pageable pageable); - - // required 값들이 넘겨준 값보다 큰 row를 조회하는 쿼리 (페이징 추가) - @Query("SELECT p FROM Project p WHERE " + - "(:requiredClient IS NULL OR p.requiredClient > :requiredClient) AND " + - "(:requiredServer IS NULL OR p.requiredServer > :requiredServer) AND " + - "(:requiredDesign IS NULL OR p.requiredDesign > :requiredDesign) AND " + - "(:requiredPlanner IS NULL OR p.requiredPlanner > :requiredPlanner) AND " + - "(:requiredAIEngineer IS NULL OR p.requiredAIEngineer > :requiredAIEngineer)") - Page findProjectsWithLargerRequirements( - @Param("requiredClient") Integer requiredClient, - @Param("requiredServer") Integer requiredServer, - @Param("requiredDesign") Integer requiredDesign, - @Param("requiredPlanner") Integer requiredPlanner, - @Param("requiredAIEngineer") Integer requiredAIEngineer, - Pageable pageable - ); + Page findProjectsByStartDateLessThanEqualOrEndDateGreaterThanEqual( + LocalDate startDate, LocalDate endDate, Pageable pageable); + ProjectIdAndContent findProjectIdAndContentByProjectId(Long projectId);