diff --git a/src/main/java/run/halo/app/controller/content/api/SheetController.java b/src/main/java/run/halo/app/controller/content/api/SheetController.java index bf657ec9a..46a129909 100644 --- a/src/main/java/run/halo/app/controller/content/api/SheetController.java +++ b/src/main/java/run/halo/app/controller/content/api/SheetController.java @@ -8,13 +8,18 @@ import org.springframework.data.web.SortDefault; import org.springframework.web.bind.annotation.*; import run.halo.app.cache.lock.CacheLock; import run.halo.app.model.dto.BaseCommentDTO; +import run.halo.app.model.entity.SheetComment; +import run.halo.app.model.enums.CommentStatus; import run.halo.app.model.params.SheetCommentParam; import run.halo.app.model.vo.BaseCommentVO; import run.halo.app.model.vo.BaseCommentWithParentVO; +import run.halo.app.model.vo.CommentWithHasChildrenVO; import run.halo.app.service.OptionService; import run.halo.app.service.SheetCommentService; import run.halo.app.service.SheetService; +import java.util.List; + import static org.springframework.data.domain.Sort.Direction.DESC; /** @@ -39,6 +44,23 @@ public class SheetController { this.optionService = optionService; } + @GetMapping("{sheetId:\\d+}/comments/top_view") + public Page listTopComments(@PathVariable("sheetId") Integer sheetId, + @RequestParam(name = "page", required = false, defaultValue = "0") int page, + @SortDefault(sort = "createTime", direction = DESC) Sort sort) { + return sheetCommentService.pageTopCommentsBy(sheetId, CommentStatus.PUBLISHED, PageRequest.of(page, optionService.getCommentPageSize(), sort)); + } + + @GetMapping("{sheetId:\\d+}/comments/{commentParentId:\\d+}/children") + public List listChildrenBy(@PathVariable("sheetId") Integer sheetId, + @PathVariable("commentParentId") Long commentParentId, + @SortDefault(sort = "createTime", direction = DESC) Sort sort) { + // Find all children comments + List sheetComments = sheetCommentService.listChildrenBy(sheetId, commentParentId, CommentStatus.PUBLISHED, sort); + // Convert to base comment dto + return sheetCommentService.convertTo(sheetComments); + } + @GetMapping("{sheetId:\\d+}/comments/tree_view") @ApiOperation("Lists comments with tree view")