mirror of https://github.com/halo-dev/halo
complete list latest posts service
parent
6b06ac4264
commit
5a1327ade7
|
@ -0,0 +1,24 @@
|
||||||
|
package cc.ryanc.halo.model.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post detail output dto.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class PostDetailOutputDTO extends PostSimpleOutputDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 源内容
|
||||||
|
*/
|
||||||
|
private String originalContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渲染后内容
|
||||||
|
*/
|
||||||
|
private String formatContent;
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
package cc.ryanc.halo.model.dto;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||||
|
import cc.ryanc.halo.model.entity.Post;
|
||||||
|
import cc.ryanc.halo.model.enums.PostCreateFrom;
|
||||||
|
import cc.ryanc.halo.model.enums.PostType;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page simple output dto.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class PostSimpleOutputDTO implements OutputConverter<PostSimpleOutputDTO, Post> {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章标题
|
||||||
|
*/
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章类型
|
||||||
|
* 0: 普通文章
|
||||||
|
* 1: 自定义页面
|
||||||
|
* 2: 日志
|
||||||
|
*/
|
||||||
|
private PostType type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 摘要
|
||||||
|
*/
|
||||||
|
private String summary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缩略图
|
||||||
|
*/
|
||||||
|
private String thumbnail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 浏览量
|
||||||
|
*/
|
||||||
|
private Long visits;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否允许评论
|
||||||
|
*/
|
||||||
|
private Boolean disallowComment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义渲染模板名称
|
||||||
|
*/
|
||||||
|
private String template;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否置顶
|
||||||
|
*/
|
||||||
|
private Integer topPriority;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布来源
|
||||||
|
*/
|
||||||
|
private PostCreateFrom createFrom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点赞量/喜欢量
|
||||||
|
*/
|
||||||
|
private Long likes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间戳
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间戳
|
||||||
|
*/
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit time.
|
||||||
|
*/
|
||||||
|
private Date editTime;
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
package cc.ryanc.halo.model.entity;
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -14,6 +16,8 @@ import java.util.Date;
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "attachments")
|
@Table(name = "attachments")
|
||||||
|
@SQLDelete(sql = "update attachments set deleted = true where id = ?")
|
||||||
|
@Where(clause = "deleted = false")
|
||||||
public class Attachment {
|
public class Attachment {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package cc.ryanc.halo.model.entity;
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -14,6 +16,8 @@ import java.util.Date;
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "galleries")
|
@Table(name = "galleries")
|
||||||
|
@SQLDelete(sql = "update galleries set deleted = true where id = ?")
|
||||||
|
@Where(clause = "deleted = false")
|
||||||
public class Gallery {
|
public class Gallery {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package cc.ryanc.halo.model.entity;
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -14,6 +16,8 @@ import java.util.Date;
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "links")
|
@Table(name = "links")
|
||||||
|
@SQLDelete(sql = "update links set deleted = true where id = ?")
|
||||||
|
@Where(clause = "deleted = false")
|
||||||
public class Link {
|
public class Link {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package cc.ryanc.halo.model.entity;
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -14,6 +16,8 @@ import java.util.Date;
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "menus")
|
@Table(name = "menus")
|
||||||
|
@SQLDelete(sql = "update menus set deleted = true where id = ?")
|
||||||
|
@Where(clause = "deleted = false")
|
||||||
public class Menu {
|
public class Menu {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|
|
@ -110,6 +110,13 @@ public class Post {
|
||||||
@Column(name = "likes", columnDefinition = "bigint default 0")
|
@Column(name = "likes", columnDefinition = "bigint default 0")
|
||||||
private Long likes;
|
private Long likes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit time.
|
||||||
|
*/
|
||||||
|
@Column(name = "edit_time", columnDefinition = "timestamp default CURRENT_TIMESTAMP")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date editTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建时间戳
|
* 创建时间戳
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package cc.ryanc.halo.model.entity;
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -14,6 +16,8 @@ import java.util.Date;
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "menus")
|
@Table(name = "menus")
|
||||||
|
@SQLDelete(sql = "update menus set deleted = true where id = ?")
|
||||||
|
@Where(clause = "deleted = false")
|
||||||
public class Tag {
|
public class Tag {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package cc.ryanc.halo.model.entity;
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -14,6 +16,8 @@ import java.util.Date;
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users")
|
@Table(name = "users")
|
||||||
|
@SQLDelete(sql = "update users set deleted = true where id = ?")
|
||||||
|
@Where(clause = "deleted = false")
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package cc.ryanc.halo.service;
|
package cc.ryanc.halo.service;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.PostSimpleOutputDTO;
|
||||||
import cc.ryanc.halo.model.entity.Post;
|
import cc.ryanc.halo.model.entity.Post;
|
||||||
import cc.ryanc.halo.service.base.CrudService;
|
import cc.ryanc.halo.service.base.CrudService;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post service.
|
* Post service.
|
||||||
|
@ -10,4 +13,13 @@ import cc.ryanc.halo.service.base.CrudService;
|
||||||
*/
|
*/
|
||||||
public interface PostService extends CrudService<Post, Integer> {
|
public interface PostService extends CrudService<Post, Integer> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists latest posts.
|
||||||
|
*
|
||||||
|
* @param top top number must not be less than 0
|
||||||
|
* @return latest posts
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
Page<PostSimpleOutputDTO> listLatest(int top);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
package cc.ryanc.halo.service.impl;
|
package cc.ryanc.halo.service.impl;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.PostSimpleOutputDTO;
|
||||||
import cc.ryanc.halo.model.entity.Post;
|
import cc.ryanc.halo.model.entity.Post;
|
||||||
import cc.ryanc.halo.repository.PostRepository;
|
import cc.ryanc.halo.repository.PostRepository;
|
||||||
import cc.ryanc.halo.service.PostService;
|
import cc.ryanc.halo.service.PostService;
|
||||||
import cc.ryanc.halo.service.base.AbstractCrudService;
|
import cc.ryanc.halo.service.base.AbstractCrudService;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post service implementation.
|
* Post service implementation.
|
||||||
|
@ -20,4 +25,15 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
||||||
super(postRepository);
|
super(postRepository);
|
||||||
this.postRepository = postRepository;
|
this.postRepository = postRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<PostSimpleOutputDTO> listLatest(int top) {
|
||||||
|
Assert.isTrue(top > 0, "Top number must not be less than 0");
|
||||||
|
|
||||||
|
PageRequest latestPageable = PageRequest.of(0, top, Sort.by(Sort.Direction.DESC, "editTime"));
|
||||||
|
|
||||||
|
Page<Post> posts = listAll(latestPageable);
|
||||||
|
|
||||||
|
return posts.map(post -> new PostSimpleOutputDTO().convertFrom(post));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package cc.ryanc.halo.web.controller.admin;
|
package cc.ryanc.halo.web.controller.admin;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.dto.PostSimpleOutputDTO;
|
||||||
import cc.ryanc.halo.service.AttachmentService;
|
import cc.ryanc.halo.service.AttachmentService;
|
||||||
import cc.ryanc.halo.service.CommentService;
|
import cc.ryanc.halo.service.CommentService;
|
||||||
import cc.ryanc.halo.service.PostService;
|
import cc.ryanc.halo.service.PostService;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -40,13 +42,14 @@ public class AdminController {
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = {"", "/index"})
|
@GetMapping(value = {"", "/index"})
|
||||||
public String admin(Model model) {
|
public String admin(Model model) {
|
||||||
final Long postsCount = postService.count();
|
|
||||||
final Long commentsCount = commentService.count();
|
|
||||||
final Long attachmentsCount = attachmentService.count();
|
|
||||||
|
|
||||||
model.addAttribute("postsCount", postsCount);
|
Page<PostSimpleOutputDTO> postPage = postService.listLatest(10);
|
||||||
model.addAttribute("commentsCount", commentsCount);
|
|
||||||
model.addAttribute("attachmentsCount", attachmentsCount);
|
model.addAttribute("postsCount", postPage.getTotalElements());
|
||||||
|
model.addAttribute("commentsCount", commentService.count());
|
||||||
|
model.addAttribute("attachmentsCount", attachmentService.count());
|
||||||
|
|
||||||
|
model.addAttribute("latestPosts", postPage.getContent());
|
||||||
return "admin/admin_index";
|
return "admin/admin_index";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue