🎨 add new post type

pull/137/head
ruibaby 2019-03-04 22:00:50 +08:00
parent ad568bed17
commit c48970a034
6 changed files with 98 additions and 3 deletions

View File

@ -56,6 +56,7 @@ public class Post implements Serializable {
* *
* post * post
* page * page
* journal
*/ */
private String postType = "post"; private String postType = "post";
@ -156,6 +157,12 @@ public class Post implements Serializable {
@ColumnDefault("0") @ColumnDefault("0")
private Integer postPriority; private Integer postPriority;
/**
*
*/
@ColumnDefault("admin")
private String postSource;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm") @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
public Date getPostDate() { public Date getPostDate() {
return postDate; return postDate;

View File

@ -18,7 +18,12 @@ public enum PostTypeEnum {
/** /**
* *
*/ */
POST_TYPE_PAGE("page"); POST_TYPE_PAGE("page"),
/**
*
*/
POST_TYPE_JOURNAL("journal");
private String desc; private String desc;

View File

@ -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;
}
}

View File

@ -59,7 +59,7 @@ public class ApiCommentController {
* @param request request * @param request request
* @return JsonResult * @return JsonResult
*/ */
@PostMapping("save") @PostMapping(value = "/save")
public JsonResult save(@Valid Comment comment, public JsonResult save(@Valid Comment comment,
@RequestParam(value = "postId") Long postId, @RequestParam(value = "postId") Long postId,
HttpServletRequest request) { HttpServletRequest request) {

View File

@ -12,7 +12,7 @@ import java.util.List;
/** /**
* <pre> * <pre>
* API * API
* </pre> * </pre>
* *
* @author : RYAN0UP * @author : RYAN0UP

View File

@ -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");
}
}