mirror of https://github.com/halo-dev/halo
🎨 代码优化
parent
12a6b548a4
commit
953dbc7fae
|
@ -0,0 +1,19 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Attachment;
|
||||
import cc.ryanc.halo.model.dto.base.AbstractOutputConverter;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019-03-10
|
||||
*/
|
||||
@Data
|
||||
public class AttachmentAdminOutputDTO extends AbstractOutputConverter<AttachmentAdminOutputDTO, Attachment> {
|
||||
|
||||
private Long attachId;
|
||||
|
||||
private String attachPath;
|
||||
|
||||
private String attachSmallPath;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.base.AbstractOutputConverter;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019-03-09
|
||||
*/
|
||||
@Data
|
||||
public class CommentAdminOutputDTO extends AbstractOutputConverter<CommentAdminOutputDTO, Comment> {
|
||||
|
||||
private Long commentId;
|
||||
|
||||
private Post post;
|
||||
|
||||
private String commentAuthor;
|
||||
|
||||
private String commentAuthorUrl;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date commentDate;
|
||||
|
||||
private String commentContent;
|
||||
|
||||
private Integer commentStatus;
|
||||
|
||||
private Integer isAdmin;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Category;
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.Tag;
|
||||
import cc.ryanc.halo.model.dto.base.AbstractOutputConverter;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Post admin output dto.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Data
|
||||
public class PostAdminOutputDTO extends AbstractOutputConverter<PostAdminOutputDTO, Post> {
|
||||
|
||||
private Long postId;
|
||||
|
||||
private String postTitle;
|
||||
|
||||
private String postType;
|
||||
|
||||
private String postUrl;
|
||||
|
||||
private List<Category> categories;
|
||||
|
||||
private List<Tag> tags;
|
||||
|
||||
private List<Comment> comments;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date postDate;
|
||||
|
||||
private Integer postStatus;
|
||||
|
||||
private Long postViews;
|
||||
|
||||
private Integer postPriority;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package cc.ryanc.halo.model.dto;
|
||||
|
||||
import cc.ryanc.halo.model.domain.*;
|
||||
import cc.ryanc.halo.model.dto.base.AbstractOutputConverter;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Post output dto for post list
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Data
|
||||
public class PostListOutputDTO extends AbstractOutputConverter<PostListOutputDTO, Post> {
|
||||
|
||||
private Long postId;
|
||||
|
||||
private User user;
|
||||
|
||||
private String postTitle;
|
||||
|
||||
private String postUrl;
|
||||
|
||||
private String postSummary;
|
||||
|
||||
private List<Category> categories;
|
||||
|
||||
private List<Tag> tags;
|
||||
|
||||
private List<Comment> comments;
|
||||
|
||||
private String postThumbnail;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
private Date postDate;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
private Date postUpdate;
|
||||
|
||||
private Long postViews;
|
||||
|
||||
private Integer allowComment;
|
||||
|
||||
private Integer postPriority;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package cc.ryanc.halo.web.controller.admin;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Attachment;
|
||||
import cc.ryanc.halo.model.dto.AttachmentAdminOutputDTO;
|
||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||
import cc.ryanc.halo.model.enums.ResultCodeEnum;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
|
@ -60,7 +61,8 @@ public class AttachmentController {
|
|||
@GetMapping
|
||||
public String attachments(Model model,
|
||||
@PageableDefault(size = 18, sort = "attachId", direction = Sort.Direction.DESC) Pageable pageable) {
|
||||
final Page<Attachment> attachments = attachmentService.listAll(pageable);
|
||||
final Page<AttachmentAdminOutputDTO> attachments = attachmentService.listAll(pageable)
|
||||
.map(attachment -> new AttachmentAdminOutputDTO().convertFrom(attachment));
|
||||
model.addAttribute("attachments", attachments);
|
||||
return "admin/admin_attachment";
|
||||
}
|
||||
|
@ -76,7 +78,8 @@ public class AttachmentController {
|
|||
@PageableDefault(size = 18, sort = "attachId", direction = Sort.Direction.DESC) Pageable pageable,
|
||||
@RequestParam(value = "id", defaultValue = "none") String id,
|
||||
@RequestParam(value = "type", defaultValue = "normal") String type) {
|
||||
final Page<Attachment> attachments = attachmentService.listAll(pageable);
|
||||
final Page<AttachmentAdminOutputDTO> attachments = attachmentService.listAll(pageable)
|
||||
.map(attachment -> new AttachmentAdminOutputDTO().convertFrom(attachment));
|
||||
model.addAttribute("attachments", attachments);
|
||||
model.addAttribute("id", id);
|
||||
if (StrUtil.equals(type, PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package cc.ryanc.halo.web.controller.admin;
|
|||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.dto.CommentAdminOutputDTO;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.*;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
|
@ -67,7 +68,8 @@ public class CommentController extends BaseController {
|
|||
public String comments(Model model,
|
||||
@PageableDefault(sort = "commentDate", direction = Sort.Direction.DESC) Pageable pageable,
|
||||
@RequestParam(value = "status", defaultValue = "0") Integer status) {
|
||||
final Page<Comment> comments = commentService.findAll(status, pageable);
|
||||
final Page<CommentAdminOutputDTO> comments = commentService.findAll(status, pageable)
|
||||
.map(comment -> new CommentAdminOutputDTO().convertFrom(comment));
|
||||
model.addAttribute("comments", comments);
|
||||
model.addAttribute("publicCount", commentService.getCountByStatus(CommentStatusEnum.PUBLISHED.getCode()));
|
||||
model.addAttribute("checkCount", commentService.getCountByStatus(CommentStatusEnum.CHECKING.getCode()));
|
||||
|
|
|
@ -2,13 +2,14 @@ package cc.ryanc.halo.web.controller.admin;
|
|||
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.dto.PostAdminOutputDTO;
|
||||
import cc.ryanc.halo.model.dto.PostViewOutputDTO;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.model.support.LogsRecord;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.enums.PostStatusEnum;
|
||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||
import cc.ryanc.halo.model.enums.ResultCodeEnum;
|
||||
import cc.ryanc.halo.model.support.JsonResult;
|
||||
import cc.ryanc.halo.model.support.LogsRecord;
|
||||
import cc.ryanc.halo.service.LogsService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.utils.BeanUtils;
|
||||
|
@ -93,7 +94,8 @@ public class PostController extends BaseController {
|
|||
public String posts(Model model,
|
||||
@RequestParam(value = "status", defaultValue = "0") Integer status,
|
||||
@PageableDefault(sort = "postDate", direction = DESC) Pageable pageable) {
|
||||
final Page<Post> posts = postService.findPostByStatus(status, PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
final Page<PostAdminOutputDTO> posts = postService.findPostByStatus(status, PostTypeEnum.POST_TYPE_POST.getDesc(), pageable)
|
||||
.map(post -> new PostAdminOutputDTO().convertFrom(post));
|
||||
model.addAttribute("posts", posts);
|
||||
model.addAttribute("publishCount", postService.getCountByStatus(PostStatusEnum.PUBLISHED.getCode()));
|
||||
model.addAttribute("draftCount", postService.getCountByStatus(PostStatusEnum.DRAFT.getCode()));
|
||||
|
@ -180,7 +182,7 @@ public class PostController extends BaseController {
|
|||
@RequestParam("tagList") String tagList) {
|
||||
//old data
|
||||
final Post oldPost = postService.fetchById(post.getPostId()).orElse(new Post());
|
||||
BeanUtils.updateProperties(oldPost,post);
|
||||
BeanUtils.updateProperties(oldPost, post);
|
||||
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
|
||||
if (null == post.getPostDate()) {
|
||||
post.setPostDate(new Date());
|
||||
|
|
|
@ -3,8 +3,9 @@ package cc.ryanc.halo.web.controller.front;
|
|||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.Tag;
|
||||
import cc.ryanc.halo.model.support.ListPage;
|
||||
import cc.ryanc.halo.model.dto.PostListOutputDTO;
|
||||
import cc.ryanc.halo.model.enums.*;
|
||||
import cc.ryanc.halo.model.support.ListPage;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.utils.CommentUtil;
|
||||
|
@ -79,7 +80,8 @@ public class FrontArchiveController extends BaseController {
|
|||
@SortDefault(sort = "postDate", direction = DESC) Sort sort) {
|
||||
//所有文章数据,分页,material主题适用
|
||||
final Pageable pageable = PageRequest.of(page - 1, 5, sort);
|
||||
final Page<Post> posts = postService.findPostByStatus(PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
final Page<PostListOutputDTO> posts = postService.findPostByStatus(PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc(), pageable)
|
||||
.map(post -> new PostListOutputDTO().convertFrom(post));
|
||||
if (null == posts) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
|
@ -100,7 +102,8 @@ public class FrontArchiveController extends BaseController {
|
|||
public String archives(Model model,
|
||||
@PathVariable(value = "year") String year,
|
||||
@PathVariable(value = "month") String month) {
|
||||
final Page<Post> posts = postService.findPostByYearAndMonth(year, month, null);
|
||||
final Page<PostListOutputDTO> posts = postService.findPostByYearAndMonth(year, month, null)
|
||||
.map(post -> new PostListOutputDTO().convertFrom(post));
|
||||
if (null == posts) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.front;
|
|||
|
||||
import cc.ryanc.halo.model.domain.Category;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.PostListOutputDTO;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.service.CategoryService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
|
@ -91,7 +92,8 @@ public class FrontCategoryController extends BaseController {
|
|||
size = Integer.parseInt(OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
}
|
||||
final Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
final Page<Post> posts = postService.findPostByCategories(category, pageable);
|
||||
final Page<PostListOutputDTO> posts = postService.findPostByCategories(category, pageable)
|
||||
.map(post -> new PostListOutputDTO().convertFrom(post));
|
||||
final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
model.addAttribute("is_categories", true);
|
||||
model.addAttribute("posts", posts);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package cc.ryanc.halo.web.controller.front;
|
||||
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.PostListOutputDTO;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
|
@ -71,7 +71,8 @@ public class FrontIndexController extends BaseController {
|
|||
}
|
||||
//所有文章数据,分页
|
||||
final Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
final Page<Post> posts = postService.findPostByStatus(pageable);
|
||||
final Page<PostListOutputDTO> posts = postService.findPostByStatus(pageable)
|
||||
.map(post -> new PostListOutputDTO().convertFrom(post));
|
||||
if (null == posts) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package cc.ryanc.halo.web.controller.front;
|
||||
|
||||
import cc.ryanc.halo.logging.Logger;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.PostListOutputDTO;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.enums.PostStatusEnum;
|
||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||
|
@ -74,7 +74,8 @@ public class FrontSearchController extends BaseController {
|
|||
size = Integer.parseInt(OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
}
|
||||
final Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
final Page<Post> posts = postService.searchPosts(HtmlUtil.escape(keyword), PostTypeEnum.POST_TYPE_POST.getDesc(), PostStatusEnum.PUBLISHED.getCode(), pageable);
|
||||
final Page<PostListOutputDTO> posts = postService.searchPosts(HtmlUtil.escape(keyword), PostTypeEnum.POST_TYPE_POST.getDesc(), PostStatusEnum.PUBLISHED.getCode(), pageable)
|
||||
.map(post -> new PostListOutputDTO().convertFrom(post));
|
||||
final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
model.addAttribute("is_search", true);
|
||||
model.addAttribute("keyword", keyword);
|
||||
|
|
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.web.controller.front;
|
|||
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.Tag;
|
||||
import cc.ryanc.halo.model.dto.PostListOutputDTO;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.service.TagService;
|
||||
|
@ -86,7 +87,8 @@ public class FrontTagController extends BaseController {
|
|||
size = Integer.parseInt(OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
}
|
||||
final Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
final Page<Post> posts = postService.findPostsByTags(tag, pageable);
|
||||
final Page<PostListOutputDTO> posts = postService.findPostsByTags(tag, pageable)
|
||||
.map(post -> new PostListOutputDTO().convertFrom(post));
|
||||
final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
model.addAttribute("is_tags", true);
|
||||
model.addAttribute("posts", posts);
|
||||
|
|
Loading…
Reference in New Issue