diff --git a/backend/src/main/java/net/pengcook/comment/controller/CommentController.java b/backend/src/main/java/net/pengcook/comment/controller/CommentController.java index cefe56c4..b1631c1d 100644 --- a/backend/src/main/java/net/pengcook/comment/controller/CommentController.java +++ b/backend/src/main/java/net/pengcook/comment/controller/CommentController.java @@ -4,7 +4,7 @@ import lombok.RequiredArgsConstructor; import net.pengcook.authentication.domain.UserInfo; import net.pengcook.authentication.resolver.LoginUser; -import net.pengcook.comment.dto.CommentResponse; +import net.pengcook.comment.dto.CommentOfRecipeResponse; import net.pengcook.comment.service.CommentService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -19,7 +19,7 @@ public class CommentController { private final CommentService commentService; @GetMapping("/{recipeId}") - public List readComments(@PathVariable long recipeId, @LoginUser UserInfo userInfo) { + public List readComments(@PathVariable long recipeId, @LoginUser UserInfo userInfo) { return commentService.readComments(recipeId, userInfo); } } diff --git a/backend/src/main/java/net/pengcook/comment/dto/CommentResponse.java b/backend/src/main/java/net/pengcook/comment/dto/CommentOfRecipeResponse.java similarity index 85% rename from backend/src/main/java/net/pengcook/comment/dto/CommentResponse.java rename to backend/src/main/java/net/pengcook/comment/dto/CommentOfRecipeResponse.java index fce3b5a4..83778907 100644 --- a/backend/src/main/java/net/pengcook/comment/dto/CommentResponse.java +++ b/backend/src/main/java/net/pengcook/comment/dto/CommentOfRecipeResponse.java @@ -4,7 +4,7 @@ import net.pengcook.authentication.domain.UserInfo; import net.pengcook.comment.domain.Comment; -public record CommentResponse( +public record CommentOfRecipeResponse( Long commentId, Long userId, String userImage, @@ -14,7 +14,7 @@ public record CommentResponse( boolean mine ) { - public CommentResponse(Comment comment, UserInfo userInfo) { + public CommentOfRecipeResponse(Comment comment, UserInfo userInfo) { this( comment.getId(), comment.getUser().getId(), diff --git a/backend/src/main/java/net/pengcook/comment/service/CommentService.java b/backend/src/main/java/net/pengcook/comment/service/CommentService.java index e87d11a3..a0eea1ac 100644 --- a/backend/src/main/java/net/pengcook/comment/service/CommentService.java +++ b/backend/src/main/java/net/pengcook/comment/service/CommentService.java @@ -4,7 +4,7 @@ import lombok.RequiredArgsConstructor; import net.pengcook.authentication.domain.UserInfo; import net.pengcook.comment.domain.Comment; -import net.pengcook.comment.dto.CommentResponse; +import net.pengcook.comment.dto.CommentOfRecipeResponse; import net.pengcook.comment.repository.CommentRepository; import org.springframework.stereotype.Service; @@ -14,11 +14,11 @@ public class CommentService { private final CommentRepository commentRepository; - public List readComments(Long recipeId, UserInfo userInfo) { + public List readComments(Long recipeId, UserInfo userInfo) { List comments = commentRepository.findByRecipeId(recipeId); return comments.stream() - .map(comment -> new CommentResponse(comment, userInfo)) + .map(comment -> new CommentOfRecipeResponse(comment, userInfo)) .toList(); } } diff --git a/backend/src/test/java/net/pengcook/comment/service/CommentServiceTest.java b/backend/src/test/java/net/pengcook/comment/service/CommentServiceTest.java index f0495a43..e39e599d 100644 --- a/backend/src/test/java/net/pengcook/comment/service/CommentServiceTest.java +++ b/backend/src/test/java/net/pengcook/comment/service/CommentServiceTest.java @@ -5,7 +5,7 @@ import java.time.LocalDateTime; import java.util.List; import net.pengcook.authentication.domain.UserInfo; -import net.pengcook.comment.dto.CommentResponse; +import net.pengcook.comment.dto.CommentOfRecipeResponse; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -25,12 +25,14 @@ class CommentServiceTest { @DisplayName("레시피의 댓글을 조회한다.") void readComments() { UserInfo userInfo = new UserInfo(1, "ela@pengcook.net"); - List expect = List.of( - new CommentResponse(1L, 2L, "loki.jpg", "loki", LocalDateTime.of(2024, 1, 1, 0, 0, 0), "great", false), - new CommentResponse(2L, 1L, "ela.jpg", "ela", LocalDateTime.of(2024, 1, 2, 0, 0, 0), "thank you", true) + List expect = List.of( + new CommentOfRecipeResponse(1L, 2L, "loki.jpg", "loki", LocalDateTime.of(2024, 1, 1, 0, 0, 0), + "great", false), + new CommentOfRecipeResponse(2L, 1L, "ela.jpg", "ela", LocalDateTime.of(2024, 1, 2, 0, 0, 0), + "thank you", true) ); - List actual = commentService.readComments(1L, userInfo); + List actual = commentService.readComments(1L, userInfo); assertThat(actual).containsExactlyInAnyOrderElementsOf(expect); }