Refactor paging latest comments

pull/146/head
johnniang 2019-05-04 10:28:18 +08:00
parent 4b812c8242
commit cbabebff68
6 changed files with 22 additions and 16 deletions

View File

@ -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

View File

@ -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);
} }

View File

@ -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());
} }

View File

@ -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_";
/** /**

View File

@ -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.

View File

@ -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