mirror of https://github.com/halo-dev/halo
Complete content api.
parent
b788dbe67e
commit
d02325b303
|
@ -23,6 +23,7 @@ import run.halo.app.model.vo.PostListVO;
|
|||
import run.halo.app.service.*;
|
||||
import run.halo.app.utils.MarkdownUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
|
|
@ -3,13 +3,19 @@ package run.halo.app.controller.content.api;
|
|||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
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.dto.JournalDTO;
|
||||
import run.halo.app.model.dto.JournalWithCmtCountDTO;
|
||||
import run.halo.app.model.entity.Journal;
|
||||
import run.halo.app.model.entity.JournalComment;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
import run.halo.app.model.enums.JournalType;
|
||||
import run.halo.app.model.params.JournalCommentParam;
|
||||
import run.halo.app.model.vo.BaseCommentVO;
|
||||
import run.halo.app.model.vo.BaseCommentWithParentVO;
|
||||
|
@ -23,8 +29,11 @@ import java.util.List;
|
|||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
/**
|
||||
* Content Journal controller.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 19-4-26
|
||||
* @author ryanwang
|
||||
* @date 2019-04-26
|
||||
*/
|
||||
@RestController("PortalJournalController")
|
||||
@RequestMapping("/api/content/journals")
|
||||
|
@ -44,6 +53,20 @@ public class JournalController {
|
|||
this.optionService = optionService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation("Lists journals")
|
||||
public Page<JournalWithCmtCountDTO> pageBy(@PageableDefault(sort = "createTime", direction = DESC) Pageable pageable) {
|
||||
Page<Journal> journals = journalService.pageBy(JournalType.PUBLIC, pageable);
|
||||
return journalService.convertToCmtCountDto(journals);
|
||||
}
|
||||
|
||||
@GetMapping("{journalId:\\d+}")
|
||||
@ApiOperation("Gets a journal detail")
|
||||
public JournalDTO getBy(@PathVariable("journalId") Integer journalId) {
|
||||
Journal journal = journalService.getById(journalId);
|
||||
return journalService.convertTo(journal);
|
||||
}
|
||||
|
||||
@GetMapping("{journalId:\\d+}/comments/top_view")
|
||||
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("journalId") Integer journalId,
|
||||
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
||||
|
|
|
@ -10,7 +10,6 @@ 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.dto.post.BasePostDetailDTO;
|
||||
import run.halo.app.model.dto.post.BasePostSimpleDTO;
|
||||
import run.halo.app.model.entity.Post;
|
||||
import run.halo.app.model.entity.PostComment;
|
||||
|
@ -55,7 +54,7 @@ public class PostController {
|
|||
|
||||
@GetMapping
|
||||
@ApiOperation("Lists posts")
|
||||
public Page<BasePostSimpleDTO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) {
|
||||
public Page<BasePostSimpleDTO> pageBy(@PageableDefault(sort = "createTime", direction = DESC) Pageable pageable) {
|
||||
Page<Post> postPage = postService.pageBy(PostStatus.PUBLISHED, pageable);
|
||||
return postService.convertToSimple(postPage);
|
||||
}
|
||||
|
@ -71,8 +70,8 @@ public class PostController {
|
|||
@GetMapping("{postId:\\d+}")
|
||||
@ApiOperation("Gets a post")
|
||||
public PostDetailVO getBy(@PathVariable("postId") Integer postId,
|
||||
@RequestParam(value = "formatDisabled", required = false, defaultValue = "true") Boolean formatDisabled,
|
||||
@RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) {
|
||||
@RequestParam(value = "formatDisabled", required = false, defaultValue = "true") Boolean formatDisabled,
|
||||
@RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) {
|
||||
PostDetailVO postDetailVO = postService.convertToDetailVo(postService.getById(postId));
|
||||
|
||||
if (formatDisabled) {
|
||||
|
|
|
@ -3,13 +3,19 @@ package run.halo.app.controller.content.api;
|
|||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
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.dto.post.BasePostDetailDTO;
|
||||
import run.halo.app.model.dto.post.BasePostSimpleDTO;
|
||||
import run.halo.app.model.entity.Sheet;
|
||||
import run.halo.app.model.entity.SheetComment;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
import run.halo.app.model.enums.PostStatus;
|
||||
import run.halo.app.model.params.SheetCommentParam;
|
||||
import run.halo.app.model.vo.BaseCommentVO;
|
||||
import run.halo.app.model.vo.BaseCommentWithParentVO;
|
||||
|
@ -26,6 +32,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
|
|||
* Sheet controller.
|
||||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @date 19-4-26
|
||||
*/
|
||||
@RestController("PortalSheetController")
|
||||
|
@ -44,6 +51,33 @@ public class SheetController {
|
|||
this.optionService = optionService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation("Lists sheets")
|
||||
public Page<BasePostSimpleDTO> pageBy(@PageableDefault(sort = "createTime", direction = DESC) Pageable pageable) {
|
||||
Page<Sheet> sheetPage = sheetService.pageBy(PostStatus.PUBLISHED, pageable);
|
||||
return sheetService.convertToSimple(sheetPage);
|
||||
}
|
||||
|
||||
@GetMapping("{sheetId:\\d+}")
|
||||
@ApiOperation("Gets a sheet")
|
||||
public BasePostDetailDTO getBy(@PathVariable("sheetId") Integer sheetId,
|
||||
@RequestParam(value = "formatDisabled", required = false, defaultValue = "true") Boolean formatDisabled,
|
||||
@RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) {
|
||||
BasePostDetailDTO sheetDetailVO = sheetService.convertToDetail(sheetService.getById(sheetId));
|
||||
|
||||
if (formatDisabled) {
|
||||
// Clear the format content
|
||||
sheetDetailVO.setFormatContent(null);
|
||||
}
|
||||
|
||||
if (sourceDisabled) {
|
||||
// Clear the original content
|
||||
sheetDetailVO.setOriginalContent(null);
|
||||
}
|
||||
|
||||
return sheetDetailVO;
|
||||
}
|
||||
|
||||
@GetMapping("{sheetId:\\d+}/comments/top_view")
|
||||
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("sheetId") Integer sheetId,
|
||||
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
|
||||
|
|
Loading…
Reference in New Issue