mirror of https://github.com/halo-dev/halo
🎨 add new post type
parent
ad568bed17
commit
c48970a034
|
@ -56,6 +56,7 @@ public class Post implements Serializable {
|
|||
* 文章类型
|
||||
* post 文章
|
||||
* page 页面
|
||||
* journal 日志
|
||||
*/
|
||||
private String postType = "post";
|
||||
|
||||
|
@ -156,6 +157,12 @@ public class Post implements Serializable {
|
|||
@ColumnDefault("0")
|
||||
private Integer postPriority;
|
||||
|
||||
/**
|
||||
* 发布来源
|
||||
*/
|
||||
@ColumnDefault("admin")
|
||||
private String postSource;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
public Date getPostDate() {
|
||||
return postDate;
|
||||
|
|
|
@ -18,7 +18,12 @@ public enum PostTypeEnum {
|
|||
/**
|
||||
* 页面
|
||||
*/
|
||||
POST_TYPE_PAGE("page");
|
||||
POST_TYPE_PAGE("page"),
|
||||
|
||||
/**
|
||||
* 日志
|
||||
*/
|
||||
POST_TYPE_JOURNAL("journal");
|
||||
|
||||
private String desc;
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package cc.ryanc.halo.model.params;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.base.AbstractInputConverter;
|
||||
import cc.ryanc.halo.utils.MarkdownUtils;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Parameter of journal.
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019/03/04
|
||||
*/
|
||||
@Data
|
||||
public class JournalParam extends AbstractInputConverter<Post> {
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 发布来源
|
||||
*/
|
||||
private String source;
|
||||
|
||||
@Override
|
||||
public Post convertTo() {
|
||||
Post post = super.convertTo();
|
||||
post.setPostContentMd(content);
|
||||
post.setPostContent(MarkdownUtils.renderMarkdown(content));
|
||||
return post;
|
||||
}
|
||||
}
|
|
@ -59,7 +59,7 @@ public class ApiCommentController {
|
|||
* @param request request
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping("save")
|
||||
@PostMapping(value = "/save")
|
||||
public JsonResult save(@Valid Comment comment,
|
||||
@RequestParam(value = "postId") Long postId,
|
||||
HttpServletRequest request) {
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* <pre>
|
||||
* 图库API
|
||||
* 图库 API
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package cc.ryanc.halo.web.controller.api;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||
import cc.ryanc.halo.model.params.JournalParam;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.utils.MarkdownUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 日志 API
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019/03/04
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/journal")
|
||||
public class ApiJournalController {
|
||||
|
||||
@Autowired
|
||||
private PostService postService;
|
||||
|
||||
/**
|
||||
* 发布日志
|
||||
*
|
||||
* @param journalParam journalParam
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/save")
|
||||
public JsonResult save(JournalParam journalParam) {
|
||||
Post post = new Post();
|
||||
post.setPostContentMd(MarkdownUtils.renderMarkdown(journalParam.getContent()));
|
||||
post.setPostSource(journalParam.getSource());
|
||||
post.setPostType(PostTypeEnum.POST_TYPE_JOURNAL.getDesc());
|
||||
post = postService.create(post);
|
||||
return JsonResult.success("ok");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue