Skip to content

Commit

Permalink
โ™ป๏ธ rename class for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
hyxrxn committed Aug 4, 2024
1 parent 179713c commit a11ff3c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +19,7 @@ public class CommentController {
private final CommentService commentService;

@GetMapping("/{recipeId}")
public List<CommentResponse> readComments(@PathVariable long recipeId, @LoginUser UserInfo userInfo) {
public List<CommentOfRecipeResponse> readComments(@PathVariable long recipeId, @LoginUser UserInfo userInfo) {
return commentService.readComments(recipeId, userInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,11 +14,11 @@ public class CommentService {

private final CommentRepository commentRepository;

public List<CommentResponse> readComments(Long recipeId, UserInfo userInfo) {
public List<CommentOfRecipeResponse> readComments(Long recipeId, UserInfo userInfo) {
List<Comment> comments = commentRepository.findByRecipeId(recipeId);

return comments.stream()
.map(comment -> new CommentResponse(comment, userInfo))
.map(comment -> new CommentOfRecipeResponse(comment, userInfo))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,12 +25,14 @@ class CommentServiceTest {
@DisplayName("๋ ˆ์‹œํ”ผ์˜ ๋Œ“๊ธ€์„ ์กฐํšŒํ•œ๋‹ค.")
void readComments() {
UserInfo userInfo = new UserInfo(1, "[email protected]");
List<CommentResponse> 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<CommentOfRecipeResponse> 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<CommentResponse> actual = commentService.readComments(1L, userInfo);
List<CommentOfRecipeResponse> actual = commentService.readComments(1L, userInfo);

assertThat(actual).containsExactlyInAnyOrderElementsOf(expect);
}
Expand Down

0 comments on commit a11ff3c

Please sign in to comment.