mirror of https://github.com/halo-dev/halo
Add draft content updation and enhance page list api
parent
f3e81b9bfb
commit
afdf94b898
|
@ -1,16 +1,19 @@
|
||||||
package run.halo.app.controller.admin.api;
|
package run.halo.app.controller.admin.api;
|
||||||
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import io.swagger.annotations.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.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.web.PageableDefault;
|
import org.springframework.data.web.PageableDefault;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import run.halo.app.cache.StringCacheStore;
|
import run.halo.app.cache.StringCacheStore;
|
||||||
|
import run.halo.app.model.dto.post.BasePostDetailDTO;
|
||||||
import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
||||||
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.enums.PostStatus;
|
import run.halo.app.model.enums.PostStatus;
|
||||||
|
import run.halo.app.model.params.PostContentParam;
|
||||||
import run.halo.app.model.params.PostParam;
|
import run.halo.app.model.params.PostParam;
|
||||||
import run.halo.app.model.params.PostQuery;
|
import run.halo.app.model.params.PostQuery;
|
||||||
import run.halo.app.model.vo.PostDetailVO;
|
import run.halo.app.model.vo.PostDetailVO;
|
||||||
|
@ -52,10 +55,15 @@ public class PostController {
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@ApiOperation("Lists posts")
|
@ApiOperation("Lists posts")
|
||||||
public Page<PostListVO> pageBy(@PageableDefault(sort = {"topPriority", "createTime"}, direction = DESC) Pageable pageable,
|
public Page<? extends BasePostSimpleDTO> pageBy(@PageableDefault(sort = {"topPriority", "createTime"}, direction = DESC) Pageable pageable,
|
||||||
PostQuery postQuery) {
|
PostQuery postQuery,
|
||||||
|
@RequestParam(value = "more", defaultValue = "true") Boolean more) {
|
||||||
Page<Post> postPage = postService.pageBy(postQuery, pageable);
|
Page<Post> postPage = postService.pageBy(postQuery, pageable);
|
||||||
return postService.convertToListVo(postPage);
|
if (more) {
|
||||||
|
return postService.convertToListVo(postPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return postService.convertToSimple(postPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("latest")
|
@GetMapping("latest")
|
||||||
|
@ -110,16 +118,24 @@ public class PostController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("{postId:\\d+}/status/{status}")
|
@PutMapping("{postId:\\d+}/status/{status}")
|
||||||
public void updateStatusBy(
|
@ApiOperation("Update post status")
|
||||||
|
public BasePostMinimalDTO updateStatusBy(
|
||||||
@PathVariable("postId") Integer postId,
|
@PathVariable("postId") Integer postId,
|
||||||
@PathVariable("status") PostStatus status) {
|
@PathVariable("status") PostStatus status) {
|
||||||
Post post = postService.getById(postId);
|
Post post = postService.updateStatus(status, postId);
|
||||||
|
|
||||||
// Set status
|
return new BasePostMinimalDTO().convertFrom(post);
|
||||||
post.setStatus(status);
|
}
|
||||||
|
|
||||||
// Update
|
@PutMapping("{postId:\\d+}/status/draft/content")
|
||||||
postService.update(post);
|
@ApiOperation("Update draft")
|
||||||
|
public BasePostDetailDTO updateDraftBy(
|
||||||
|
@PathVariable("postId") Integer postId,
|
||||||
|
@RequestBody PostContentParam contentParam) {
|
||||||
|
// Update draft content
|
||||||
|
Post post = postService.updateDraftContent(contentParam.getContent(), postId);
|
||||||
|
|
||||||
|
return new BasePostDetailDTO().convertFrom(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("{postId:\\d+}")
|
@DeleteMapping("{postId:\\d+}")
|
||||||
|
@ -128,7 +144,8 @@ public class PostController {
|
||||||
postService.removeById(postId);
|
postService.removeById(postId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("preview/{postId:\\d+}")
|
@GetMapping(value = {"preview/{postId:\\d+}", "{postId:\\d+}/preview"})
|
||||||
|
@ApiOperation("Get preview link")
|
||||||
public String preview(@PathVariable("postId") Integer postId) {
|
public String preview(@PathVariable("postId") Integer postId) {
|
||||||
Post post = postService.getById(postId);
|
Post post = postService.getById(postId);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue