mirror of https://github.com/halo-dev/halo
Refactor paging latest comments
parent
4b812c8242
commit
cbabebff68
|
@ -43,8 +43,10 @@ public class JournalCommentController {
|
|||
}
|
||||
|
||||
@GetMapping("latest")
|
||||
public List<JournalCommentWithJournalVO> listLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||
return journalCommentService.convertToWithJournalVo(journalCommentService.pageLatest(top).getContent());
|
||||
public List<JournalCommentWithJournalVO> listLatest(@RequestParam(name = "top", defaultValue = "10") int top,
|
||||
@RequestParam(name = "status", required = false) CommentStatus status) {
|
||||
List<JournalComment> latestComments = journalCommentService.pageLatest(top, status).getContent();
|
||||
return journalCommentService.convertToWithJournalVo(latestComments);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
|
|
|
@ -43,16 +43,12 @@ public class PostCommentController {
|
|||
|
||||
@GetMapping("latest")
|
||||
@ApiOperation("Pages latest comments")
|
||||
public List<PostCommentWithPostVO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||
List<PostComment> content = postCommentService.pageLatest(top).getContent();
|
||||
return postCommentService.convertToWithPostVo(content);
|
||||
}
|
||||
|
||||
@GetMapping("latest/{status}")
|
||||
@ApiOperation("Pages latest comments by status")
|
||||
public List<PostCommentWithPostVO> pageLatest(@RequestParam(name = "top", defaultValue = "10") int top,
|
||||
@PathVariable("status") CommentStatus status) {
|
||||
@RequestParam(name = "status", required = false) CommentStatus status) {
|
||||
// Get latest comment
|
||||
List<PostComment> content = postCommentService.pageLatest(top, status).getContent();
|
||||
|
||||
// Convert and return
|
||||
return postCommentService.convertToWithPostVo(content);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,8 +41,9 @@ public class SheetCommentController {
|
|||
}
|
||||
|
||||
@GetMapping("latest")
|
||||
public List<SheetCommentWithSheetVO> listLatest(@RequestParam(name = "top", defaultValue = "10") int top) {
|
||||
Page<SheetComment> sheetCommentPage = sheetCommentService.pageLatest(top);
|
||||
public List<SheetCommentWithSheetVO> listLatest(@RequestParam(name = "top", defaultValue = "10") int top,
|
||||
@RequestParam(name = "status", required = false) CommentStatus status) {
|
||||
Page<SheetComment> sheetCommentPage = sheetCommentService.pageLatest(top, status);
|
||||
return sheetCommentService.convertToWithPostVo(sheetCommentPage.getContent());
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,9 @@ public interface ThemeService {
|
|||
*/
|
||||
String THEMES_CACHE_KEY = "themes";
|
||||
|
||||
/**
|
||||
* Custom sheet prefix.
|
||||
*/
|
||||
String CUSTOM_SHEET_PREFIX = "sheet_";
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,7 +59,7 @@ public interface BaseCommentService<COMMENT extends BaseComment> extends CrudSer
|
|||
* @return a page of comments
|
||||
*/
|
||||
@NonNull
|
||||
Page<COMMENT> pageLatest(int top, CommentStatus status);
|
||||
Page<COMMENT> pageLatest(int top, @Nullable CommentStatus status);
|
||||
|
||||
/**
|
||||
* Pages comments.
|
||||
|
|
|
@ -75,12 +75,16 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
|
|||
|
||||
@Override
|
||||
public Page<COMMENT> pageLatest(int top) {
|
||||
return listAll(ServiceUtils.buildLatestPageable(top));
|
||||
return pageLatest(top, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<COMMENT> pageLatest(int top,CommentStatus status){
|
||||
return baseCommentRepository.findAllByStatus(status,ServiceUtils.buildLatestPageable(top));
|
||||
public Page<COMMENT> pageLatest(int top, CommentStatus status) {
|
||||
if (status == null) {
|
||||
return listAll(ServiceUtils.buildLatestPageable(top));
|
||||
}
|
||||
|
||||
return baseCommentRepository.findAllByStatus(status, ServiceUtils.buildLatestPageable(top));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue