未验证 提交 44d740b7 编写于 作者: 扶醉 提交者: GitHub

Fix number of comment in detail of post and sheet and add it into detail of journal (#1503)

上级 0a137136
......@@ -71,7 +71,7 @@ public class JournalController {
@GetMapping("{journalId:\\d+}")
@ApiOperation("Gets a journal detail")
public JournalDTO getBy(@PathVariable("journalId") Integer journalId) {
public JournalWithCmtCountDTO getBy(@PathVariable("journalId") Integer journalId) {
Journal journal = journalService.getById(journalId);
return journalService.convertTo(journal);
}
......
......@@ -99,6 +99,15 @@ public interface BaseCommentRepository<COMMENT extends BaseComment>
*/
long countByPostId(@NonNull Integer postId);
/**
* Count comments by comment status and post id.
*
* @param status status must not be null
* @param postId post id must not be null.
* @return comments count
*/
long countByStatusAndPostId(@NonNull CommentStatus status, @NonNull Integer postId);
/**
* Counts by comment status.
*
......
......@@ -68,13 +68,13 @@ public interface JournalService extends CrudService<Journal, Integer> {
Page<Journal> pageBy(@NonNull JournalType type, @NonNull Pageable pageable);
/**
* Converts to journal dto.
* Converts to journal with comment count dto.
*
* @param journal journal must not be null
* @return journal dto
* @return journal with comment count dto
*/
@NonNull
JournalDTO convertTo(@NonNull Journal journal);
JournalWithCmtCountDTO convertTo(@NonNull Journal journal);
/**
* Converts to journal with comment count dto list.
......
......@@ -144,6 +144,15 @@ public interface BaseCommentService<COMMENT extends BaseComment>
*/
long countByPostId(@NonNull Integer postId);
/**
* Count comments by comment status and post id.
*
* @param status status must not be null.
* @param postId post id must not be null.
* @return comments count
*/
long countByStatusAndPostId(@NonNull CommentStatus status, @NonNull Integer postId);
/**
* Counts by comment status.
*
......
......@@ -290,6 +290,12 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment>
return baseCommentRepository.countByPostId(postId);
}
@Override
public long countByStatusAndPostId(@NonNull CommentStatus status, @NonNull Integer postId) {
Assert.notNull(postId, "Post id must not be null");
return baseCommentRepository.countByStatusAndPostId(status, postId);
}
@Override
public long countByStatus(@NonNull CommentStatus status) {
return baseCommentRepository.countByStatus(status);
......
......@@ -107,10 +107,16 @@ public class JournalServiceImpl extends AbstractCrudService<Journal, Integer>
}
@Override
public JournalDTO convertTo(Journal journal) {
public JournalWithCmtCountDTO convertTo(Journal journal) {
Assert.notNull(journal, "Journal must not be null");
return new JournalDTO().convertFrom(journal);
JournalWithCmtCountDTO journalWithCmtCountDto = new JournalWithCmtCountDTO()
.convertFrom(journal);
journalWithCmtCountDto.setCommentCount(journalCommentService.countByStatusAndPostId(
CommentStatus.PUBLISHED, journal.getId()));
return journalWithCmtCountDto;
}
@Override
......
......@@ -787,7 +787,8 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
postDetailVO.setMetaIds(metaIds);
postDetailVO.setMetas(postMetaService.convertTo(postMetaList));
postDetailVO.setCommentCount(postCommentService.countByPostId(post.getId()));
postDetailVO.setCommentCount(postCommentService.countByStatusAndPostId(
CommentStatus.PUBLISHED, post.getId()));
postDetailVO.setFullPath(buildFullPath(post));
......
......@@ -341,7 +341,8 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
sheetDetailVO.setSummary(generateSummary(sheet.getFormatContent()));
}
sheetDetailVO.setCommentCount(sheetCommentService.countByPostId(sheet.getId()));
sheetDetailVO.setCommentCount(sheetCommentService.countByStatusAndPostId(
CommentStatus.PUBLISHED, sheet.getId()));
sheetDetailVO.setFullPath(buildFullPath(sheet));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册