Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ order comment list by newest first #447

Open
wants to merge 2 commits into
base: be/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package net.pengcook.comment.service;

import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import lombok.RequiredArgsConstructor;
import net.pengcook.authentication.domain.UserInfo;
import net.pengcook.comment.domain.Comment;
import net.pengcook.comment.dto.CommentOfUserResponse;
import net.pengcook.comment.dto.CommentOfRecipeResponse;
import net.pengcook.comment.dto.CommentOfUserResponse;
import net.pengcook.comment.dto.CreateCommentRequest;
import net.pengcook.comment.exception.NotFoundException;
import net.pengcook.comment.exception.UnauthorizedDeletionException;
Expand Down Expand Up @@ -79,6 +80,7 @@ public List<CommentOfUserResponse> readCommentsOfUserV1(UserInfo userInfo) {

return comments.stream()
.map(CommentOfUserResponse::new)
.sorted(Comparator.comparing(CommentOfUserResponse::createdAt).reversed())
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ void deleteCommentsByUser() {
void readCommentsOfUser() {
UserInfo userInfo = new UserInfo(2, "[email protected]");
List<CommentOfUserResponse> expect = List.of(
new CommentOfUserResponse(1L, 1L, "김밥", "김밥이미지.jpg", LocalDateTime.of(2024, 1, 1, 0, 0, 0), "great"),
new CommentOfUserResponse(3L, 2L, "김치찌개", "김치찌개이미지.jpg", LocalDateTime.of(2024, 5, 5, 0, 0, 0), "good")
new CommentOfUserResponse(3L, 2L, "김치찌개", "김치찌개이미지.jpg", LocalDateTime.of(2024, 5, 5, 0, 0, 0), "good"),
new CommentOfUserResponse(1L, 1L, "김밥", "김밥이미지.jpg", LocalDateTime.of(2024, 1, 1, 0, 0, 0), "great")
);

List<CommentOfUserResponse> actual = commentService.readCommentsOfUserV1(userInfo);

assertThat(actual).containsExactlyInAnyOrderElementsOf(expect);
assertThat(actual).containsExactlyElementsOf(expect);
}
}
Loading