Complete journal list and creation api

pull/146/head
johnniang 2019-04-26 00:32:10 +08:00
parent 6e56732cf4
commit e8ba507717
3 changed files with 70 additions and 33 deletions

View File

@ -1,33 +0,0 @@
package run.halo.app.controller.content.api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import run.halo.app.model.dto.BaseCommentDTO;
import run.halo.app.model.params.PostCommentParam;
import run.halo.app.service.PostCommentService;
/**
* Portal comment controller.
*
* @author johnniang
* @date 4/3/19
*/
@RestController("ApiContentCommentController")
@RequestMapping("/api/comments")
public class CommentController {
private final PostCommentService postCommentService;
public CommentController(PostCommentService postCommentService) {
this.postCommentService = postCommentService;
}
@PostMapping
@ApiOperation("Comments a post")
public BaseCommentDTO comment(@RequestBody PostCommentParam postCommentParam) {
return postCommentService.convertTo(postCommentService.createBy(postCommentParam));
}
}

View File

@ -0,0 +1,62 @@
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.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.*;
import run.halo.app.model.dto.BaseCommentDTO;
import run.halo.app.model.params.JournalCommentParam;
import run.halo.app.model.vo.BaseCommentVO;
import run.halo.app.model.vo.BaseCommentWithParentVO;
import run.halo.app.service.JournalCommentService;
import run.halo.app.service.JournalService;
import run.halo.app.service.OptionService;
import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* @author johnniang
* @date 19-4-26
*/
@RestController("PortalJournalController")
@RequestMapping("/api/journals")
public class JournalController {
private final JournalService journalService;
private final JournalCommentService journalCommentService;
private final OptionService optionService;
public JournalController(JournalService journalService,
JournalCommentService journalCommentService,
OptionService optionService) {
this.journalService = journalService;
this.journalCommentService = journalCommentService;
this.optionService = optionService;
}
@GetMapping("{sheetId:\\d+}/comments/tree_view")
@ApiOperation("Lists comments with tree view")
public Page<BaseCommentVO> listCommentsTree(@PathVariable("sheetId") Integer sheetId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return journalCommentService.pageVosBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
@GetMapping("{sheetId:\\d+}/comments/list_view")
@ApiOperation("Lists comment with list view")
public Page<BaseCommentWithParentVO> listComments(@PathVariable("sheetId") Integer sheetId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return journalCommentService.pageWithParentVoBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
@PostMapping("comments")
@ApiOperation("Comments a post")
public BaseCommentDTO comment(@RequestBody JournalCommentParam journalCommentParam) {
return journalCommentService.convertTo(journalCommentService.createBy(journalCommentParam));
}
}

View File

@ -8,10 +8,12 @@ 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.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.enums.PostStatus;
import run.halo.app.model.params.PostCommentParam;
import run.halo.app.model.vo.BaseCommentVO;
import run.halo.app.model.vo.BaseCommentWithParentVO;
import run.halo.app.service.OptionService;
@ -87,6 +89,12 @@ public class PostController {
return postCommentService.pageWithParentVoBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
}
@PostMapping("comments")
@ApiOperation("Comments a post")
public BaseCommentDTO comment(@RequestBody PostCommentParam postCommentParam) {
return postCommentService.convertTo(postCommentService.createBy(postCommentParam));
}
@PostMapping("{postId:\\d+}/likes")
@ApiOperation("Likes a post")
public void like(@PathVariable("postId") Integer postId) {