mirror of https://github.com/halo-dev/halo
Build base structure of mixed entities
parent
df276066db
commit
819c999dcf
|
@ -0,0 +1,138 @@
|
|||
package run.halo.app.model.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* Base comment entity.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Entity(name = "BaseComment")
|
||||
@Table(name = "comments")
|
||||
@SQLDelete(sql = "update comments set deleted = true where id = ?")
|
||||
@Where(clause = "deleted = false")
|
||||
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER, columnDefinition = "int default 0")
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class BaseComment extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* Commentator's name.
|
||||
*/
|
||||
@Column(name = "author", columnDefinition = "varchar(50) not null")
|
||||
private String author;
|
||||
|
||||
/**
|
||||
* Commentator's email.
|
||||
*/
|
||||
@Column(name = "email", columnDefinition = "varchar(255) not null")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* Commentator's ip address.
|
||||
*/
|
||||
@Column(name = "ip_address", columnDefinition = "varchar(127) default ''")
|
||||
private String ipAddress;
|
||||
|
||||
/**
|
||||
* Commentator's website.
|
||||
*/
|
||||
@Column(name = "author_url", columnDefinition = "varchar(512) default ''")
|
||||
private String authorUrl;
|
||||
|
||||
/**
|
||||
* Gavatar md5
|
||||
*/
|
||||
@Column(name = "gavatar_md5", columnDefinition = "varchar(128) default ''")
|
||||
private String gavatarMd5;
|
||||
|
||||
/**
|
||||
* Comment content.
|
||||
*/
|
||||
@Column(name = "content", columnDefinition = "varchar(1023) not null")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* Comment status.
|
||||
*/
|
||||
@Column(name = "status", columnDefinition = "int default 1")
|
||||
private CommentStatus status;
|
||||
|
||||
/**
|
||||
* Commentator's userAgent.
|
||||
*/
|
||||
@Column(name = "user_agent", columnDefinition = "varchar(512) default ''")
|
||||
private String userAgent;
|
||||
|
||||
/**
|
||||
* Is admin's comment.
|
||||
*/
|
||||
@Column(name = "is_admin", columnDefinition = "tinyint default 0")
|
||||
private Boolean isAdmin;
|
||||
|
||||
/**
|
||||
* Post id.
|
||||
*/
|
||||
@Column(name = "post_id", columnDefinition = "int not null")
|
||||
private Integer postId;
|
||||
|
||||
/**
|
||||
* Whether to top the comment.
|
||||
*/
|
||||
@Column(name = "top_priority", columnDefinition = "int default 0")
|
||||
private Integer topPriority;
|
||||
|
||||
/**
|
||||
* Parent comment.
|
||||
*/
|
||||
@Column(name = "parent_id", columnDefinition = "bigint default 0")
|
||||
private Long parentId;
|
||||
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
|
||||
if (parentId == null || parentId < 0) {
|
||||
parentId = 0L;
|
||||
}
|
||||
|
||||
if (ipAddress == null) {
|
||||
ipAddress = "";
|
||||
}
|
||||
|
||||
if (authorUrl == null) {
|
||||
authorUrl = "";
|
||||
}
|
||||
|
||||
if (gavatarMd5 == null) {
|
||||
gavatarMd5 = "";
|
||||
}
|
||||
|
||||
if (status == null) {
|
||||
status = CommentStatus.AUDITING;
|
||||
}
|
||||
|
||||
if (userAgent == null) {
|
||||
userAgent = "";
|
||||
}
|
||||
|
||||
if (isAdmin == null) {
|
||||
isAdmin = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -17,13 +17,13 @@ import java.util.Date;
|
|||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Entity(name = "base_post")
|
||||
@Entity(name = "BasePost")
|
||||
@Table(name = "posts", indexes = @Index(columnList = "url"))
|
||||
@SQLDelete(sql = "update posts set deleted = true where id = ?")
|
||||
@Where(clause = "deleted = false")
|
||||
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER, columnDefinition = "int default 0")
|
||||
@Data
|
||||
@ToString
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class BasePost extends BaseEntity {
|
||||
|
||||
|
|
|
@ -1,137 +1,15 @@
|
|||
package run.halo.app.model.entity;
|
||||
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* Comment entity.
|
||||
*
|
||||
* @author johnniang
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "comments")
|
||||
@SQLDelete(sql = "update comments set deleted = true where id = ?")
|
||||
@Where(clause = "deleted = false")
|
||||
@Data
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Comment extends BaseEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* Commentator's name.
|
||||
*/
|
||||
@Column(name = "author", columnDefinition = "varchar(50) not null")
|
||||
private String author;
|
||||
|
||||
/**
|
||||
* Commentator's email.
|
||||
*/
|
||||
@Column(name = "email", columnDefinition = "varchar(255) not null")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* Commentator's ip address.
|
||||
*/
|
||||
@Column(name = "ip_address", columnDefinition = "varchar(127) default ''")
|
||||
private String ipAddress;
|
||||
|
||||
/**
|
||||
* Commentator's website.
|
||||
*/
|
||||
@Column(name = "author_url", columnDefinition = "varchar(512) default ''")
|
||||
private String authorUrl;
|
||||
|
||||
/**
|
||||
* Gavatar md5
|
||||
*/
|
||||
@Column(name = "gavatar_md5", columnDefinition = "varchar(128) default ''")
|
||||
private String gavatarMd5;
|
||||
|
||||
/**
|
||||
* Comment content.
|
||||
*/
|
||||
@Column(name = "content", columnDefinition = "varchar(1023) not null")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* Comment status.
|
||||
*/
|
||||
@Column(name = "status", columnDefinition = "int default 1")
|
||||
private CommentStatus status;
|
||||
|
||||
/**
|
||||
* Commentator's userAgent.
|
||||
*/
|
||||
@Column(name = "user_agent", columnDefinition = "varchar(512) default ''")
|
||||
private String userAgent;
|
||||
|
||||
/**
|
||||
* Is admin's comment.
|
||||
*/
|
||||
@Column(name = "is_admin", columnDefinition = "tinyint default 0")
|
||||
private Boolean isAdmin;
|
||||
|
||||
/**
|
||||
* Post id.
|
||||
*/
|
||||
@Column(name = "post_id", columnDefinition = "int not null")
|
||||
private Integer postId;
|
||||
|
||||
/**
|
||||
* Whether to top the comment.
|
||||
*/
|
||||
@Column(name = "top_priority", columnDefinition = "int default 0")
|
||||
private Integer topPriority;
|
||||
|
||||
/**
|
||||
* Parent comment.
|
||||
*/
|
||||
@Column(name = "parent_id", columnDefinition = "bigint default 0")
|
||||
private Long parentId;
|
||||
|
||||
@Override
|
||||
public void prePersist() {
|
||||
super.prePersist();
|
||||
id = null;
|
||||
|
||||
if (parentId == null || parentId < 0) {
|
||||
parentId = 0L;
|
||||
}
|
||||
|
||||
if (ipAddress == null) {
|
||||
ipAddress = "";
|
||||
}
|
||||
|
||||
if (authorUrl == null) {
|
||||
authorUrl = "";
|
||||
}
|
||||
|
||||
if (gavatarMd5 == null) {
|
||||
gavatarMd5 = "";
|
||||
}
|
||||
|
||||
if (status == null) {
|
||||
status = CommentStatus.AUDITING;
|
||||
}
|
||||
|
||||
if (userAgent == null) {
|
||||
userAgent = "";
|
||||
}
|
||||
|
||||
if (isAdmin == null) {
|
||||
isAdmin = false;
|
||||
}
|
||||
|
||||
}
|
||||
@Entity(name = "Comment")
|
||||
@DiscriminatorValue("0")
|
||||
public class Comment extends BaseComment {
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@ import javax.persistence.Entity;
|
|||
*/
|
||||
@Entity(name = "Journal")
|
||||
@DiscriminatorValue("2")
|
||||
public class Journal extends BasePost {
|
||||
public class Journal extends BaseComment {
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package run.halo.app.model.entity;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* Sheet comment.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 19-4-24
|
||||
*/
|
||||
@Entity(name = "SheetComment")
|
||||
@DiscriminatorValue("1")
|
||||
public class SheetComment extends BaseComment {
|
||||
|
||||
}
|
|
@ -1,15 +1,13 @@
|
|||
package run.halo.app.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import run.halo.app.model.entity.Comment;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
import run.halo.app.model.projection.CommentCountProjection;
|
||||
import run.halo.app.repository.base.BaseRepository;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import run.halo.app.model.entity.Comment;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
import run.halo.app.model.projection.CommentCountProjection;
|
||||
import run.halo.app.repository.base.BaseCommentRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -19,17 +17,7 @@ import java.util.List;
|
|||
* @author johnniang
|
||||
* @date 3/21/19
|
||||
*/
|
||||
public interface CommentRepository extends BaseRepository<Comment, Long>, JpaSpecificationExecutor<Comment> {
|
||||
|
||||
/**
|
||||
* Finds all comments by status.
|
||||
*
|
||||
* @param status status must not be null
|
||||
* @param pageable page info must not be null
|
||||
* @return a page of comment
|
||||
*/
|
||||
@NonNull
|
||||
Page<Comment> findAllByStatus(@Nullable CommentStatus status, @NonNull Pageable pageable);
|
||||
public interface CommentRepository extends BaseCommentRepository<Comment> {
|
||||
|
||||
/**
|
||||
* Finds all comments by post ids.
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package run.halo.app.repository;
|
||||
|
||||
import run.halo.app.model.entity.Journal;
|
||||
import run.halo.app.repository.base.BasePostRepository;
|
||||
import run.halo.app.repository.base.BasePostRepository;
|
||||
import run.halo.app.repository.base.BaseCommentRepository;
|
||||
|
||||
/**
|
||||
* Journal repository.
|
||||
|
@ -10,6 +9,6 @@ import run.halo.app.repository.base.BasePostRepository;
|
|||
* @author johnniang
|
||||
* @date 3/22/19
|
||||
*/
|
||||
public interface JournalRepository extends BasePostRepository<Journal> {
|
||||
public interface JournalRepository extends BaseCommentRepository<Journal> {
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package run.halo.app.repository;
|
||||
|
||||
import run.halo.app.model.entity.SheetComment;
|
||||
import run.halo.app.repository.base.BaseCommentRepository;
|
||||
|
||||
/**
|
||||
* Sheet comment repository.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 19-4-24
|
||||
*/
|
||||
public interface SheetCommentRepository extends BaseCommentRepository<SheetComment> {
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@ import run.halo.app.model.entity.Sheet;
|
|||
import run.halo.app.repository.base.BasePostRepository;
|
||||
|
||||
/**
|
||||
* Page repository.
|
||||
* Sheet repository.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/22/19
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package run.halo.app.repository.base;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import run.halo.app.model.entity.BaseComment;
|
||||
import run.halo.app.model.enums.CommentStatus;
|
||||
|
||||
/**
|
||||
* Base comment repository.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 19-4-24
|
||||
*/
|
||||
public interface BaseCommentRepository<DOMAIN extends BaseComment> extends BaseRepository<DOMAIN, Long>, JpaSpecificationExecutor<DOMAIN> {
|
||||
|
||||
/**
|
||||
* Finds all comments by status.
|
||||
*
|
||||
* @param status status must not be null
|
||||
* @param pageable page info must not be null
|
||||
* @return a page of comment
|
||||
*/
|
||||
@NonNull
|
||||
Page<DOMAIN> findAllByStatus(@Nullable CommentStatus status, @NonNull Pageable pageable);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package run.halo.app.service;
|
||||
|
||||
import run.halo.app.model.entity.Journal;
|
||||
import run.halo.app.service.base.CrudService;
|
||||
|
||||
/**
|
||||
* Journal service interface.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 19-4-24
|
||||
*/
|
||||
public interface JournalService extends CrudService<Journal, Long> {
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package run.halo.app.service;
|
||||
|
||||
import run.halo.app.model.entity.SheetComment;
|
||||
import run.halo.app.service.base.CrudService;
|
||||
|
||||
/**
|
||||
* Sheet comment service interface.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 19-4-24
|
||||
*/
|
||||
public interface SheetCommentService extends CrudService<SheetComment, Long> {
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package run.halo.app.service;
|
||||
|
||||
import run.halo.app.model.entity.Sheet;
|
||||
import run.halo.app.service.base.CrudService;
|
||||
|
||||
/**
|
||||
* Sheet service interface.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 19-4-24
|
||||
*/
|
||||
public interface SheetService extends CrudService<Sheet, Integer> {
|
||||
|
||||
}
|
Loading…
Reference in New Issue