mirror of https://github.com/halo-dev/halo
Also create entity for the better halo
parent
d7b5bf2e49
commit
e5dfa4ab9f
|
@ -1,10 +1,15 @@
|
||||||
language: java
|
language: java
|
||||||
jdk:
|
jdk:
|
||||||
- oraclejdk8
|
- oraclejdk8
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- .autoconf
|
||||||
|
- $HOME/.m2
|
||||||
script:
|
script:
|
||||||
- mvn clean package -Pci
|
- mvn clean package -Pci
|
||||||
branches:
|
branches:
|
||||||
only:
|
only:
|
||||||
- master
|
- master
|
||||||
notifications:
|
notifications:
|
||||||
webhooks: https://fathomless-fjord-24024.herokuapp.com/notify
|
webhooks:
|
||||||
|
- https://fathomless-fjord-24024.herokuapp.com/notify
|
||||||
|
|
|
@ -6,7 +6,6 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
|
||||||
import org.springframework.data.annotation.LastModifiedDate;
|
import org.springframework.data.annotation.LastModifiedDate;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Category entity.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "categories")
|
||||||
|
@SQLDelete(sql = "update categories set deleted = true where id = ?")
|
||||||
|
@Where(clause = "deleted = false")
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class Category {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIME")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIME")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@Column(name = "deleted", columnDefinition = "tinyint default 0")
|
||||||
|
private Boolean deleted;
|
||||||
|
|
||||||
|
@Column(name = "name", columnDefinition = "varchar(50) not null")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "snake_name", columnDefinition = "varchar(50) not null")
|
||||||
|
private String snakeName;
|
||||||
|
|
||||||
|
@Column(name = "description", columnDefinition = "varchar(100) default ''")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Column(name = "parent_id", columnDefinition = "int default 0")
|
||||||
|
private Integer parentId;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comment entity.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "comments")
|
||||||
|
@SQLDelete(sql = "update comments set deleted = true where id = ?")
|
||||||
|
@Where(clause = "deleted = false")
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class Comment {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIME")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIME")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@Column(name = "deleted", columnDefinition = "tinyint default 0")
|
||||||
|
private Boolean deleted;
|
||||||
|
|
||||||
|
@Column(name = "author", columnDefinition = "varchar(50) not null")
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
@Column(name = "email", columnDefinition = "varchar(50) default ''")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Column(name = "ip_address", columnDefinition = "varchar(127) default ''")
|
||||||
|
private String ipAddress;
|
||||||
|
|
||||||
|
@Column(name = "gavatar_md5", columnDefinition = "varchar(128) default ''")
|
||||||
|
private String gavatarMd5;
|
||||||
|
|
||||||
|
@Column(name = "content", columnDefinition = "varchar(1024) not null")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@Column(name = "user_agent", columnDefinition = "varchar(512) default ''")
|
||||||
|
private String userAgent;
|
||||||
|
|
||||||
|
@Column(name = "is_admin", columnDefinition = "tinyint default 0")
|
||||||
|
private Boolean isAdmin;
|
||||||
|
|
||||||
|
@Column(name = "parent_id", columnDefinition = "bigint default 0")
|
||||||
|
private Long parentId;
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.entity.enums.LogType;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log entity.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "logs")
|
||||||
|
@SQLDelete(sql = "update logs set deleted = true where id = ?")
|
||||||
|
@Where(clause = "deleted = false")
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class Log {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIME")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIME")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@Column(name = "deleted", columnDefinition = "tinyint default 0")
|
||||||
|
private Boolean deleted;
|
||||||
|
|
||||||
|
@Column(name = "log_key", columnDefinition = "varchar(1023) default ''")
|
||||||
|
private String logKey;
|
||||||
|
|
||||||
|
@Column(name = "type", columnDefinition = "int not null")
|
||||||
|
private LogType type;
|
||||||
|
|
||||||
|
@Column(name = "content", columnDefinition = "varchar(1023) not null")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@Column(name = "ip_address", columnDefinition = "varchar(127) default ''")
|
||||||
|
private String ipAddress;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setting entity.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "options")
|
||||||
|
@SQLDelete(sql = "update options set deleted = true where id = ?")
|
||||||
|
@Where(clause = "deleted = false")
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class Option {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIME")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIME")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@Column(name = "deleted", columnDefinition = "TINYINT default 0")
|
||||||
|
private Boolean deleted;
|
||||||
|
|
||||||
|
@Column(name = "option_key", columnDefinition = "varchar(100) not null")
|
||||||
|
private String optionKey;
|
||||||
|
|
||||||
|
@Column(name = "option_value", columnDefinition = "varchar(1023) not null")
|
||||||
|
private String optionValue;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
|
import cc.ryanc.halo.model.entity.enums.PostCreateFrom;
|
||||||
|
import cc.ryanc.halo.model.entity.enums.PostType;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post entity.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "posts")
|
||||||
|
@SQLDelete(sql = "update posts set deleted = true where id = ?")
|
||||||
|
@Where(clause = "deleted = false")
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class Post {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIME")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIME")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@Column(name = "deleted", columnDefinition = "tinyint default 0")
|
||||||
|
private Boolean deleted;
|
||||||
|
|
||||||
|
@Column(name = "title", columnDefinition = "varchar(100) not null")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Column(name = "type", columnDefinition = "int default 0")
|
||||||
|
private PostType type;
|
||||||
|
|
||||||
|
@Column(name = "original_content", columnDefinition = "text not null")
|
||||||
|
private String originalContent;
|
||||||
|
|
||||||
|
@Column(name = "format_content", columnDefinition = "text not null")
|
||||||
|
private String formatContent;
|
||||||
|
|
||||||
|
@Column(name = "summary", columnDefinition = "varchar(500) default ''")
|
||||||
|
private String summary;
|
||||||
|
|
||||||
|
@Column(name = "thumbnail", columnDefinition = "varchar(1023) default ''")
|
||||||
|
private String thumbnail;
|
||||||
|
|
||||||
|
@Column(name = "visits", columnDefinition = "bigint default 0")
|
||||||
|
private Long visits;
|
||||||
|
|
||||||
|
@Column(name = "disallow_comment", columnDefinition = "int default 0")
|
||||||
|
private Boolean disallowComment;
|
||||||
|
|
||||||
|
@Column(name = "password", columnDefinition = "varchar(255) default ''")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Column(name = "template", columnDefinition = "varchar(255) default ''")
|
||||||
|
private String template;
|
||||||
|
|
||||||
|
@Column(name = "top_priority", columnDefinition = "int default 0")
|
||||||
|
private Integer topPriority;
|
||||||
|
|
||||||
|
@Column(name = "create_from", columnDefinition = "int default 0")
|
||||||
|
private PostCreateFrom createFrom;
|
||||||
|
|
||||||
|
@Column(name = "likes", columnDefinition = "bigint default 0")
|
||||||
|
private Long likes;
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package cc.ryanc.halo.model.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.SQLDelete;
|
||||||
|
import org.hibernate.annotations.Where;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post category entity.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "post_categories")
|
||||||
|
@SQLDelete(sql = "update post_categories set deleted = true where id = ?")
|
||||||
|
@Where(clause = "deleted = false")
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class PostCategory {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(name = "create_time", columnDefinition = "timestamp default CURRENT_TIME")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@Column(name = "update_time", columnDefinition = "timestamp default CURRENT_TIME")
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
@Column(name = "deleted", columnDefinition = "tinyint default 0")
|
||||||
|
private Boolean deleted;
|
||||||
|
|
||||||
|
@Column(name = "category_id")
|
||||||
|
private Integer categoryId;
|
||||||
|
|
||||||
|
@Column(name = "post_id")
|
||||||
|
private Integer postId;
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package cc.ryanc.halo.model.entity.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comment status.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
public enum CommentStatus implements ValueEnum<Integer> {
|
||||||
|
|
||||||
|
PUBLISHED(0),
|
||||||
|
AUDITING(1),
|
||||||
|
RECYCLE(2);
|
||||||
|
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
CommentStatus(Integer value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package cc.ryanc.halo.model.entity.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log type.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
public enum LogType implements ValueEnum<Integer> {
|
||||||
|
;
|
||||||
|
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
LogType(Integer value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package cc.ryanc.halo.model.entity.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post create from type.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
public enum PostCreateFrom implements ValueEnum<Integer> {
|
||||||
|
|
||||||
|
ADMIN(0),
|
||||||
|
WECHAT(1);
|
||||||
|
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
PostCreateFrom(Integer value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package cc.ryanc.halo.model.entity.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post type.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
public enum PostType implements ValueEnum<Integer> {
|
||||||
|
|
||||||
|
POST(0),
|
||||||
|
PAGE(1),
|
||||||
|
JOURNAL(2);
|
||||||
|
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
PostType(Integer value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package cc.ryanc.halo.model.entity.enums;
|
||||||
|
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for value enum.
|
||||||
|
*
|
||||||
|
* @param <T> value type
|
||||||
|
* @author johnniang
|
||||||
|
*/
|
||||||
|
public interface ValueEnum<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get enum value.
|
||||||
|
*
|
||||||
|
* @return enum value
|
||||||
|
*/
|
||||||
|
T getValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert value to corresponding enum.
|
||||||
|
*
|
||||||
|
* @param enumType enum type
|
||||||
|
* @param value database value
|
||||||
|
* @param <V> value generic
|
||||||
|
* @param <E> enum generic
|
||||||
|
* @return corresponding enum
|
||||||
|
*/
|
||||||
|
static <V, E extends ValueEnum<V>> E valueToEnum(Class<E> enumType, V value) {
|
||||||
|
Assert.notNull(enumType, "enum type must not be null");
|
||||||
|
Assert.notNull(value, "value must not be null");
|
||||||
|
Assert.isTrue(enumType.isEnum(), "type must be an enum type");
|
||||||
|
|
||||||
|
return Stream.of(enumType.getEnumConstants())
|
||||||
|
.filter(item -> item.getValue().equals(value))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("unknown database value: " + value));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue