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