Skip to content

Commit

Permalink
Complete content api.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Sep 23, 2019
1 parent b788dbe commit d02325b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import run.halo.app.service.*;
import run.halo.app.utils.MarkdownUtils;

import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
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;
Expand All @@ -23,8 +29,11 @@
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")
Expand All @@ -44,6 +53,20 @@ public JournalController(JournalService journalService,
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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;
Expand Down Expand Up @@ -55,7 +54,7 @@ public PostController(PostService postService,

@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);
}
Expand All @@ -71,8 +70,8 @@ public Page<BasePostSimpleDTO> pageBy(@RequestParam(value = "keyword") String ke
@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
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;
Expand All @@ -26,6 +32,7 @@
* Sheet controller.
*
* @author johnniang
* @author ryanwang
* @date 19-4-26
*/
@RestController("PortalSheetController")
Expand All @@ -44,6 +51,33 @@ public SheetController(SheetService sheetService, SheetCommentService sheetComme
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,
Expand Down

0 comments on commit d02325b

Please sign in to comment.