mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 22:21:09 +08:00
feat: show post participants
This commit is contained in:
@@ -128,6 +128,9 @@ public class PostController {
|
||||
.collect(Collectors.toList());
|
||||
dto.setComments(comments);
|
||||
|
||||
java.util.List<com.openisle.model.User> participants = commentService.getParticipants(post.getId(), 5);
|
||||
dto.setParticipants(participants.stream().map(this::toAuthorDto).collect(Collectors.toList()));
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
@@ -219,6 +222,7 @@ public class PostController {
|
||||
private long views;
|
||||
private List<CommentDto> comments;
|
||||
private List<ReactionDto> reactions;
|
||||
private java.util.List<AuthorDto> participants;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -13,4 +13,7 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
|
||||
List<Comment> findByParentOrderByCreatedAtAsc(Comment parent);
|
||||
List<Comment> findByAuthorOrderByCreatedAtDesc(User author, Pageable pageable);
|
||||
List<Comment> findByContentContainingIgnoreCase(String keyword);
|
||||
|
||||
@org.springframework.data.jpa.repository.Query("SELECT DISTINCT c.author FROM Comment c WHERE c.post = :post")
|
||||
java.util.List<User> findDistinctAuthorsByPost(@org.springframework.data.repository.query.Param("post") Post post);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,16 @@ public class CommentService {
|
||||
return commentRepository.findByAuthorOrderByCreatedAtDesc(user, pageable);
|
||||
}
|
||||
|
||||
public java.util.List<User> getParticipants(Long postId, int limit) {
|
||||
Post post = postRepository.findById(postId)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Post not found"));
|
||||
java.util.LinkedHashSet<User> set = new java.util.LinkedHashSet<>();
|
||||
set.add(post.getAuthor());
|
||||
set.addAll(commentRepository.findDistinctAuthorsByPost(post));
|
||||
java.util.List<User> list = new java.util.ArrayList<>(set);
|
||||
return list.subList(0, Math.min(limit, list.size()));
|
||||
}
|
||||
|
||||
public java.util.List<Comment> getCommentsByIds(java.util.List<Long> ids) {
|
||||
return commentRepository.findAllById(ids);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user