mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-18 21:10:57 +08:00
feat: show correct reply counts
This commit is contained in:
@@ -19,6 +19,7 @@ public class PostSummaryDto {
|
||||
private CategoryDto category;
|
||||
private List<TagDto> tags;
|
||||
private long views;
|
||||
private long commentCount;
|
||||
private PostStatus status;
|
||||
private LocalDateTime pinnedAt;
|
||||
private LocalDateTime lastReplyAt;
|
||||
|
||||
@@ -58,6 +58,7 @@ public class PostMapper {
|
||||
dto.setCategory(categoryMapper.toDto(post.getCategory()));
|
||||
dto.setTags(post.getTags().stream().map(tagMapper::toDto).collect(Collectors.toList()));
|
||||
dto.setViews(post.getViews());
|
||||
dto.setCommentCount(commentService.countComments(post.getId()));
|
||||
dto.setStatus(post.getStatus());
|
||||
dto.setPinnedAt(post.getPinnedAt());
|
||||
|
||||
|
||||
@@ -27,4 +27,7 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
|
||||
@org.springframework.data.jpa.repository.Query("SELECT MAX(c.createdAt) FROM Comment c WHERE c.author.id = :userId")
|
||||
java.time.LocalDateTime findLastCommentTimeOfUserByUserId(@org.springframework.data.repository.query.Param("userId") Long userId);
|
||||
|
||||
@org.springframework.data.jpa.repository.Query("SELECT COUNT(c) FROM Comment c WHERE c.post.id = :postId")
|
||||
long countByPostId(@org.springframework.data.repository.query.Param("postId") Long postId);
|
||||
|
||||
}
|
||||
|
||||
@@ -186,6 +186,13 @@ public class CommentService {
|
||||
return time;
|
||||
}
|
||||
|
||||
public long countComments(Long postId) {
|
||||
log.debug("countComments called for post {}", postId);
|
||||
long count = commentRepository.countByPostId(postId);
|
||||
log.debug("countComments for post {} is {}", postId, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteComment(String username, Long id) {
|
||||
log.debug("deleteComment called by user {} for comment {}", username, id);
|
||||
|
||||
Reference in New Issue
Block a user