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

pull/1528/head
扶醉 2021-10-29 19:36:09 +08:00 committed by GitHub
parent 0a137136ce
commit 44d740b760
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 40 additions and 8 deletions

View File

@ -71,7 +71,7 @@ public class JournalController {
@GetMapping("{journalId:\\d+}") @GetMapping("{journalId:\\d+}")
@ApiOperation("Gets a journal detail") @ApiOperation("Gets a journal detail")
public JournalDTO getBy(@PathVariable("journalId") Integer journalId) { public JournalWithCmtCountDTO getBy(@PathVariable("journalId") Integer journalId) {
Journal journal = journalService.getById(journalId); Journal journal = journalService.getById(journalId);
return journalService.convertTo(journal); return journalService.convertTo(journal);
} }

View File

@ -99,6 +99,15 @@ public interface BaseCommentRepository<COMMENT extends BaseComment>
*/ */
long countByPostId(@NonNull Integer postId); 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. * Counts by comment status.
* *

View File

@ -68,13 +68,13 @@ public interface JournalService extends CrudService<Journal, Integer> {
Page<Journal> pageBy(@NonNull JournalType type, @NonNull Pageable pageable); 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 * @param journal journal must not be null
* @return journal dto * @return journal with comment count dto
*/ */
@NonNull @NonNull
JournalDTO convertTo(@NonNull Journal journal); JournalWithCmtCountDTO convertTo(@NonNull Journal journal);
/** /**
* Converts to journal with comment count dto list. * Converts to journal with comment count dto list.

View File

@ -144,6 +144,15 @@ public interface BaseCommentService<COMMENT extends BaseComment>
*/ */
long countByPostId(@NonNull Integer postId); 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. * Counts by comment status.
* *

View File

@ -290,6 +290,12 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment>
return baseCommentRepository.countByPostId(postId); 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 @Override
public long countByStatus(@NonNull CommentStatus status) { public long countByStatus(@NonNull CommentStatus status) {
return baseCommentRepository.countByStatus(status); return baseCommentRepository.countByStatus(status);

View File

@ -107,10 +107,16 @@ public class JournalServiceImpl extends AbstractCrudService<Journal, Integer>
} }
@Override @Override
public JournalDTO convertTo(Journal journal) { public JournalWithCmtCountDTO convertTo(Journal journal) {
Assert.notNull(journal, "Journal must not be null"); 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 @Override

View File

@ -787,7 +787,8 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
postDetailVO.setMetaIds(metaIds); postDetailVO.setMetaIds(metaIds);
postDetailVO.setMetas(postMetaService.convertTo(postMetaList)); postDetailVO.setMetas(postMetaService.convertTo(postMetaList));
postDetailVO.setCommentCount(postCommentService.countByPostId(post.getId())); postDetailVO.setCommentCount(postCommentService.countByStatusAndPostId(
CommentStatus.PUBLISHED, post.getId()));
postDetailVO.setFullPath(buildFullPath(post)); postDetailVO.setFullPath(buildFullPath(post));

View File

@ -341,7 +341,8 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
sheetDetailVO.setSummary(generateSummary(sheet.getFormatContent())); sheetDetailVO.setSummary(generateSummary(sheet.getFormatContent()));
} }
sheetDetailVO.setCommentCount(sheetCommentService.countByPostId(sheet.getId())); sheetDetailVO.setCommentCount(sheetCommentService.countByStatusAndPostId(
CommentStatus.PUBLISHED, sheet.getId()));
sheetDetailVO.setFullPath(buildFullPath(sheet)); sheetDetailVO.setFullPath(buildFullPath(sheet));