Complete content api.

pull/316/head
ruibaby 2019-09-23 20:28:38 +08:00
parent b788dbe67e
commit d02325b303
4 changed files with 62 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import run.halo.app.model.vo.PostListVO;
import run.halo.app.service.*; import run.halo.app.service.*;
import run.halo.app.utils.MarkdownUtils; import run.halo.app.utils.MarkdownUtils;
import java.io.File;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;

View File

@ -3,13 +3,19 @@ package run.halo.app.controller.content.api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.data.web.SortDefault; import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import run.halo.app.cache.lock.CacheLock; import run.halo.app.cache.lock.CacheLock;
import run.halo.app.model.dto.BaseCommentDTO; 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.entity.JournalComment;
import run.halo.app.model.enums.CommentStatus; 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.params.JournalCommentParam;
import run.halo.app.model.vo.BaseCommentVO; import run.halo.app.model.vo.BaseCommentVO;
import run.halo.app.model.vo.BaseCommentWithParentVO; import run.halo.app.model.vo.BaseCommentWithParentVO;
@ -23,8 +29,11 @@ import java.util.List;
import static org.springframework.data.domain.Sort.Direction.DESC; import static org.springframework.data.domain.Sort.Direction.DESC;
/** /**
* Content Journal controller.
*
* @author johnniang * @author johnniang
* @date 19-4-26 * @author ryanwang
* @date 2019-04-26
*/ */
@RestController("PortalJournalController") @RestController("PortalJournalController")
@RequestMapping("/api/content/journals") @RequestMapping("/api/content/journals")
@ -44,6 +53,20 @@ public class JournalController {
this.optionService = optionService; 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") @GetMapping("{journalId:\\d+}/comments/top_view")
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("journalId") Integer journalId, public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("journalId") Integer journalId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page, @RequestParam(name = "page", required = false, defaultValue = "0") int page,

View File

@ -10,7 +10,6 @@ import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import run.halo.app.cache.lock.CacheLock; import run.halo.app.cache.lock.CacheLock;
import run.halo.app.model.dto.BaseCommentDTO; 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.dto.post.BasePostSimpleDTO;
import run.halo.app.model.entity.Post; import run.halo.app.model.entity.Post;
import run.halo.app.model.entity.PostComment; import run.halo.app.model.entity.PostComment;
@ -55,7 +54,7 @@ public class PostController {
@GetMapping @GetMapping
@ApiOperation("Lists posts") @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); Page<Post> postPage = postService.pageBy(PostStatus.PUBLISHED, pageable);
return postService.convertToSimple(postPage); return postService.convertToSimple(postPage);
} }
@ -71,8 +70,8 @@ public class PostController {
@GetMapping("{postId:\\d+}") @GetMapping("{postId:\\d+}")
@ApiOperation("Gets a post") @ApiOperation("Gets a post")
public PostDetailVO getBy(@PathVariable("postId") Integer postId, public PostDetailVO getBy(@PathVariable("postId") Integer postId,
@RequestParam(value = "formatDisabled", required = false, defaultValue = "true") Boolean formatDisabled, @RequestParam(value = "formatDisabled", required = false, defaultValue = "true") Boolean formatDisabled,
@RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) { @RequestParam(value = "sourceDisabled", required = false, defaultValue = "false") Boolean sourceDisabled) {
PostDetailVO postDetailVO = postService.convertToDetailVo(postService.getById(postId)); PostDetailVO postDetailVO = postService.convertToDetailVo(postService.getById(postId));
if (formatDisabled) { if (formatDisabled) {

View File

@ -3,13 +3,19 @@ package run.halo.app.controller.content.api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.data.web.SortDefault; import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import run.halo.app.cache.lock.CacheLock; import run.halo.app.cache.lock.CacheLock;
import run.halo.app.model.dto.BaseCommentDTO; 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.entity.SheetComment;
import run.halo.app.model.enums.CommentStatus; 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.params.SheetCommentParam;
import run.halo.app.model.vo.BaseCommentVO; import run.halo.app.model.vo.BaseCommentVO;
import run.halo.app.model.vo.BaseCommentWithParentVO; import run.halo.app.model.vo.BaseCommentWithParentVO;
@ -26,6 +32,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
* Sheet controller. * Sheet controller.
* *
* @author johnniang * @author johnniang
* @author ryanwang
* @date 19-4-26 * @date 19-4-26
*/ */
@RestController("PortalSheetController") @RestController("PortalSheetController")
@ -44,6 +51,33 @@ public class SheetController {
this.optionService = optionService; 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") @GetMapping("{sheetId:\\d+}/comments/top_view")
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("sheetId") Integer sheetId, public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("sheetId") Integer sheetId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page, @RequestParam(name = "page", required = false, defaultValue = "0") int page,