mirror of https://github.com/halo-dev/halo
Fix number of comment in detail of post and sheet and add it into detail of journal (#1503)
parent
0a137136ce
commit
44d740b760
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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));
|
||||||
|
|
||||||
|
|
|
@ -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));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue