-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Feature] 인기 있는 토론방 조회 API 및 최근 의견이 달린 토론방 API 구현 #85
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -521,6 +521,110 @@ public void getTalkRoomsRelatedBookTotalSize() { | |
assertThat(anotherTotalCount).isEqualTo(10L); | ||
} | ||
|
||
@Test | ||
@DisplayName("최근 의견이 달린 토론방을 가져온다.") | ||
void fetchRecentCommentedDiscussions() throws Exception { | ||
// given | ||
User user = createUser(); | ||
userRepository.save(user); | ||
|
||
Book book = createBook(); | ||
bookRepository.save(book); | ||
|
||
List<TalkRoom> talkRooms = IntStream.range(1, 11) | ||
.mapToObj(i -> TalkRoom.builder() | ||
.user(user) | ||
.book(book) | ||
.title("토론방" + i) | ||
.content("내용" + i) | ||
.build()) | ||
.toList(); | ||
talkRoomRepository.saveAll(talkRooms); | ||
|
||
List<Comment> comments = IntStream.range(3, 6) | ||
.mapToObj(i -> Comment.builder() | ||
.user(user) | ||
.talkRoom(talkRooms.get(i)) | ||
.content("의견") | ||
.build()) | ||
.toList(); | ||
commentRepository.saveAll(comments); | ||
|
||
SearchServiceRequest request = SearchServiceRequest.builder() | ||
.size(3) | ||
.page(1) | ||
.order("recent-comment") | ||
.build(); | ||
|
||
// when | ||
List<TalkRoomQueryResponse> response = talkRoomRepository.findAllTalkRoom(request.getOffset(), | ||
request.getSize(), request.getOrder(), request.getQuery()); | ||
|
||
// then | ||
assertThat("토론방6").isEqualTo(response.get(0).getTitle()); | ||
assertThat("토론방5").isEqualTo(response.get(1).getTitle()); | ||
assertThat("토론방4").isEqualTo(response.get(2).getTitle()); | ||
} | ||
|
||
@Test | ||
@DisplayName("최근 의견이 달린 토론방을 가져온다.") | ||
void fetchRecentCommentedDiscussions2() throws Exception { | ||
// given | ||
User user = createUser(); | ||
userRepository.save(user); | ||
|
||
Book book = createBook(); | ||
bookRepository.save(book); | ||
|
||
List<TalkRoom> talkRooms = IntStream.range(1, 11) | ||
.mapToObj(i -> TalkRoom.builder() | ||
.user(user) | ||
.book(book) | ||
.title("토론방" + i) | ||
.content("내용" + i) | ||
.build()) | ||
.toList(); | ||
talkRoomRepository.saveAll(talkRooms); | ||
|
||
Comment comment1 = Comment.builder() | ||
.content("의견") | ||
.user(user) | ||
.talkRoom(talkRooms.get(3)) | ||
.build(); | ||
Comment comment2 = Comment.builder() | ||
.content("의견") | ||
.user(user) | ||
.talkRoom(talkRooms.get(4)) | ||
.build(); | ||
Comment comment3 = Comment.builder() | ||
.content("의견") | ||
.user(user) | ||
.talkRoom(talkRooms.get(5)) | ||
.build(); | ||
Comment comment4 = Comment.builder() | ||
.content("의견 추가") | ||
.user(user) | ||
.talkRoom(talkRooms.get(5)) | ||
.build(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment 생성 메서드가 있는데 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 생성 메서드는 TalkRoom 0번 객체에만 만들어지기 때문에 여러 TalkRoom방에 Comment를 생성하기 위해 이렇게 작성했습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment comment1 = createComment(talkRooms.get(3), user);
Comment comment2 = createComment(talkRooms.get(4), user);
Comment comment3 = createComment(talkRooms.get(5), user);
Comment comment4 = createcomment(talkRooms.get(5), user);
commentRepository.saveAll(List.of(comment1, comment2, comment3, comment4)); 위와 같이 작성하면 되지 않을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 수정 해서 다시 올렸습니다! |
||
|
||
commentRepository.saveAll(List.of(comment1, comment2, comment3, comment4)); | ||
|
||
SearchServiceRequest request = SearchServiceRequest.builder() | ||
.size(3) | ||
.page(1) | ||
.order("recent-comment") | ||
.build(); | ||
|
||
// when | ||
List<TalkRoomQueryResponse> response = talkRoomRepository.findAllTalkRoom(request.getOffset(), | ||
request.getSize(), request.getOrder(), request.getQuery()); | ||
|
||
// then | ||
assertThat("토론방6").isEqualTo(response.get(0).getTitle()); | ||
assertThat("토론방5").isEqualTo(response.get(1).getTitle()); | ||
assertThat("토론방4").isEqualTo(response.get(2).getTitle()); | ||
} | ||
|
||
private static Comment createComment(TalkRoom talkRoom, User user) { | ||
return Comment.builder() | ||
.talkRoom(talkRoom) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orderType
이RECENT_COMMENT
일 때max
로 정렬 조건을 지정한 이유가 있을까요?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max
를 사용하지 않고gropBy
를 TalkRoom.id 로 하니 에러가 발생하더라구요. 그래서gropBy
를 없애고comment.createDateTime.max().desc()
해결이 되어서 일단은 이렇게 작성해놨습니다!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 알겠습니다!