add. post相关数据结构
This commit is contained in:
parent
4249468d27
commit
fdef2eaa38
21
src/main/java/com/lk/paopao/dto/CommentContentDto.java
Normal file
21
src/main/java/com/lk/paopao/dto/CommentContentDto.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.lk.paopao.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import lombok.Value;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* DTO for {@link com.lk.paopao.entity.CommentContent}
|
||||
*/
|
||||
@Value
|
||||
public class CommentContentDto implements Serializable {
|
||||
Long id;
|
||||
String content;
|
||||
Byte type;
|
||||
Integer sort;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long createdOn;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long modifiedOn;
|
||||
}
|
29
src/main/java/com/lk/paopao/dto/CommentDto.java
Normal file
29
src/main/java/com/lk/paopao/dto/CommentDto.java
Normal file
@ -0,0 +1,29 @@
|
||||
package com.lk.paopao.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import lombok.Value;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DTO for {@link com.lk.paopao.entity.Comment}
|
||||
*/
|
||||
@Value
|
||||
public class CommentDto implements Serializable {
|
||||
Long id;
|
||||
Long userId;
|
||||
Long postId;
|
||||
String ip;
|
||||
String ipLoc;
|
||||
Boolean isEssence;
|
||||
Integer replyCount;
|
||||
Integer thumbsUpCount;
|
||||
Integer thumbsDownCount;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long createdOn;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long modifiedOn;
|
||||
UserDto user;
|
||||
List<CommentContentDto> contents;
|
||||
}
|
27
src/main/java/com/lk/paopao/dto/CommentReplyDto.java
Normal file
27
src/main/java/com/lk/paopao/dto/CommentReplyDto.java
Normal file
@ -0,0 +1,27 @@
|
||||
package com.lk.paopao.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class CommentReplyDto {
|
||||
|
||||
Long id;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long createdOn;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long modifiedOn;
|
||||
|
||||
Long commentId;
|
||||
|
||||
UserDto user;
|
||||
|
||||
String content;
|
||||
|
||||
String ip;
|
||||
|
||||
String ipLoc;
|
||||
|
||||
Integer thumbsUpCount;
|
||||
Integer thumbsDownCount;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.lk.paopao.dto;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 将毫秒转换为秒的Json序列化器。
|
||||
* 此序列化器将数值类型的毫秒数转换为对应的秒数进行JSON序列化。
|
||||
*/
|
||||
public class MillisecondToSecondSerializer extends JsonSerializer<Number> {
|
||||
|
||||
/**
|
||||
* 序列化方法,将输入的毫秒数转换为秒数后写入JSON生成器。
|
||||
*
|
||||
* @param value 需要序列化的毫秒数,类型为Number。
|
||||
* @param gen JSON生成器,用于输出序列化后的结果。
|
||||
* @param serializers 序列化提供者,提供序列化过程所需的额外服务。
|
||||
* @throws IOException 如果在序列化过程中发生IO异常。
|
||||
*/
|
||||
@Override
|
||||
public void serialize(Number value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
if (value != null) {
|
||||
// 将输入的毫秒数转换为秒数
|
||||
long microseconds = value.longValue();
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(microseconds);
|
||||
// 将转换后的秒数写入JSON生成器
|
||||
gen.writeNumber(seconds);
|
||||
}
|
||||
}
|
||||
}
|
16
src/main/java/com/lk/paopao/dto/PostCollectionDto.java
Normal file
16
src/main/java/com/lk/paopao/dto/PostCollectionDto.java
Normal file
@ -0,0 +1,16 @@
|
||||
package com.lk.paopao.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class PostCollectionDto {
|
||||
|
||||
Long id;
|
||||
PostDto post;
|
||||
UserDto user;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long createdOn;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long modifiedOn;
|
||||
}
|
22
src/main/java/com/lk/paopao/dto/PostContentDto.java
Normal file
22
src/main/java/com/lk/paopao/dto/PostContentDto.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.lk.paopao.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import lombok.Value;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* DTO for {@link com.lk.paopao.entity.PostContent}
|
||||
*/
|
||||
@Value
|
||||
public class PostContentDto implements Serializable {
|
||||
Long id;
|
||||
Long postId;
|
||||
String content;
|
||||
Byte type;
|
||||
Integer sort;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long createdOn;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long modifiedOn;
|
||||
}
|
37
src/main/java/com/lk/paopao/dto/PostDto.java
Normal file
37
src/main/java/com/lk/paopao/dto/PostDto.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.lk.paopao.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import lombok.Value;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DTO for {@link com.lk.paopao.entity.Post}
|
||||
*/
|
||||
@Value
|
||||
public class PostDto implements Serializable {
|
||||
Long id;
|
||||
Long userId;
|
||||
Long commentCount;
|
||||
Long collectionCount;
|
||||
Long upvoteCount;
|
||||
Long shareCount;
|
||||
Byte visibility;
|
||||
Boolean isTop;
|
||||
Boolean isEssence;
|
||||
Boolean isLock;
|
||||
Long latestRepliedOn;
|
||||
String tags;
|
||||
Long attachmentPrice;
|
||||
String ip;
|
||||
String ipLoc;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long createdOn;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long modifiedOn;
|
||||
Long deletedOn;
|
||||
Byte isDel;
|
||||
UserDto user;
|
||||
List<PostContentDto> contents;
|
||||
}
|
15
src/main/java/com/lk/paopao/dto/PostStarDto.java
Normal file
15
src/main/java/com/lk/paopao/dto/PostStarDto.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.lk.paopao.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
public class PostStarDto {
|
||||
Long id;
|
||||
PostDto post;
|
||||
UserDto user;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long createdOn;
|
||||
@JsonSerialize(using = MillisecondToSecondSerializer.class)
|
||||
Long modifiedOn;
|
||||
}
|
19
src/main/java/com/lk/paopao/dto/TagDto.java
Normal file
19
src/main/java/com/lk/paopao/dto/TagDto.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.lk.paopao.dto;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* DTO for {@link com.lk.paopao.entity.Tag}
|
||||
*/
|
||||
@Value
|
||||
public class TagDto implements Serializable {
|
||||
Long id;
|
||||
Long userId;
|
||||
UserDto user;
|
||||
String tag;
|
||||
Long quoteNum;
|
||||
Long createdOn;
|
||||
Long modifiedOn;
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.lk.paopao.dto.rest.request;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class ContentInPostRequest {
|
||||
private String content;
|
||||
private Integer sort;
|
||||
private Byte type;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.lk.paopao.dto.rest.request;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class PostRequest {
|
||||
private Long attachmentPrice;
|
||||
private Byte visibility;
|
||||
//帖子内容列表
|
||||
List<ContentInPostRequest> contents;
|
||||
// #标签列表
|
||||
List<String> tags;
|
||||
// @用户列表
|
||||
List<String> users;
|
||||
|
||||
}
|
35
src/main/java/com/lk/paopao/dto/rest/response/Paged.java
Normal file
35
src/main/java/com/lk/paopao/dto/rest/response/Paged.java
Normal file
@ -0,0 +1,35 @@
|
||||
package com.lk.paopao.dto.rest.response;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description 分页数据
|
||||
* @param <T>
|
||||
*/
|
||||
@Getter
|
||||
public class Paged<T> implements Serializable {
|
||||
|
||||
List<T> list;
|
||||
Pager pager;
|
||||
|
||||
public Paged(List<T> list, Long totalRows, Integer page, Integer pageSize){
|
||||
this.list = list;
|
||||
pager = new Pager(page, pageSize, totalRows);
|
||||
}
|
||||
|
||||
@Getter
|
||||
public class Pager implements Serializable{
|
||||
Integer page;
|
||||
Integer pageSize;
|
||||
Long totalRows;
|
||||
|
||||
public Pager(Integer page, Integer pageSize, Long totalRows){
|
||||
this.page = page;
|
||||
this.pageSize = pageSize;
|
||||
this.totalRows = totalRows;
|
||||
}
|
||||
}
|
||||
}
|
43
src/main/java/com/lk/paopao/entity/BaseAuditingEntity.java
Normal file
43
src/main/java/com/lk/paopao/entity/BaseAuditingEntity.java
Normal file
@ -0,0 +1,43 @@
|
||||
package com.lk.paopao.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@MappedSuperclass
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public abstract class BaseAuditingEntity implements Serializable {
|
||||
|
||||
// 主键ID
|
||||
@Comment("ID")
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Comment("创建时间")
|
||||
@Column(name = "created_on", nullable = false)
|
||||
@CreatedDate
|
||||
private Long createdOn;
|
||||
|
||||
@Comment("修改时间")
|
||||
@LastModifiedDate
|
||||
@Column(name = "modified_on", nullable = false)
|
||||
private Long modifiedOn;
|
||||
|
||||
@Comment("删除时间")
|
||||
@Column(name = "deleted_on")
|
||||
private Long deletedOn;
|
||||
|
||||
@Comment("是否删除 0 为未删除、1 为已删除")
|
||||
@Column(name = "is_del")
|
||||
private byte isDel = 0;
|
||||
|
||||
}
|
66
src/main/java/com/lk/paopao/entity/Comment.java
Normal file
66
src/main/java/com/lk/paopao/entity/Comment.java
Normal file
@ -0,0 +1,66 @@
|
||||
package com.lk.paopao.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@org.hibernate.annotations.Comment("评论")
|
||||
@Entity
|
||||
@Table(name = "p_comment", indexes = {
|
||||
@Index(name = "idx_comment_post_id", columnList = "post_id"),
|
||||
@Index(name = "idx_comment_user_id", columnList = "user_id")
|
||||
})
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class Comment extends BaseAuditingEntity{
|
||||
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
@org.hibernate.annotations.Comment("POST ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "post_id", nullable = false)
|
||||
private Post post;
|
||||
|
||||
@org.hibernate.annotations.Comment("用户ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private User user;
|
||||
|
||||
@OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY,mappedBy = "comment")
|
||||
private List<CommentContent> contents;
|
||||
|
||||
@org.hibernate.annotations.Comment("IP地址")
|
||||
@Column(name = "ip", length = 15)
|
||||
private String ip;
|
||||
|
||||
@org.hibernate.annotations.Comment("IP城市地址")
|
||||
@Column(name = "ip_loc", length = 64)
|
||||
private String ipLoc;
|
||||
|
||||
@org.hibernate.annotations.Comment("是否精选")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "is_essence", nullable = false)
|
||||
private Boolean isEssence = false;
|
||||
|
||||
@org.hibernate.annotations.Comment("回复数")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "reply_count", nullable = false)
|
||||
private Integer replyCount = 0;
|
||||
|
||||
@org.hibernate.annotations.Comment("点赞数")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "thumbs_up_count", nullable = false)
|
||||
private Integer thumbsUpCount = 0;
|
||||
|
||||
@org.hibernate.annotations.Comment("点踩数")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "thumbs_down_count", nullable = false)
|
||||
private Integer thumbsDownCount = 0;
|
||||
|
||||
}
|
49
src/main/java/com/lk/paopao/entity/CommentContent.java
Normal file
49
src/main/java/com/lk/paopao/entity/CommentContent.java
Normal file
@ -0,0 +1,49 @@
|
||||
package com.lk.paopao.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Comment("评论内容")
|
||||
@Entity
|
||||
@Table(name = "p_comment_content", indexes = {
|
||||
@Index(name = "idx_comment_content_comment_id", columnList = "comment_id"),
|
||||
@Index(name = "idx_comment_content_user_id", columnList = "user_id"),
|
||||
@Index(name = "idx_comment_content_type", columnList = "type"),
|
||||
@Index(name = "idx_comment_content_sort", columnList = "sort")
|
||||
})
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class CommentContent extends BaseAuditingEntity{
|
||||
|
||||
@Comment("评论ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "comment_id")
|
||||
private com.lk.paopao.entity.Comment comment;
|
||||
|
||||
@Comment("用户ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id")
|
||||
private User user;
|
||||
|
||||
@Comment("内容")
|
||||
@ColumnDefault("")
|
||||
@Column(name = "content", nullable = false, length = 4000)
|
||||
private String content;
|
||||
|
||||
@Comment("类型,1标题,2文字段落,3图片地址,4视频地址,5语音地址,6链接地址")
|
||||
@ColumnDefault("2")
|
||||
@Column(name = "type", nullable = false)
|
||||
private Byte type = 2;
|
||||
|
||||
@Comment("排序,越小越靠前")
|
||||
@ColumnDefault("100")
|
||||
@Column(name = "sort", nullable = false)
|
||||
private Integer sort = 100;
|
||||
}
|
53
src/main/java/com/lk/paopao/entity/CommentReply.java
Normal file
53
src/main/java/com/lk/paopao/entity/CommentReply.java
Normal file
@ -0,0 +1,53 @@
|
||||
package com.lk.paopao.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Comment("评论回复")
|
||||
@Entity
|
||||
@Table(name = "p_comment_reply", indexes = {
|
||||
@Index(name = "idx_comment_reply_comment_id", columnList = "comment_id")
|
||||
})
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class CommentReply extends BaseAuditingEntity{
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
@Comment("评论ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "comment_id", nullable = false)
|
||||
private com.lk.paopao.entity.Comment comment;
|
||||
|
||||
@Comment("用户ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private User user;
|
||||
|
||||
@Comment("内容")
|
||||
@Column(name = "content", nullable = false, length = 4000)
|
||||
private String content;
|
||||
|
||||
@Comment("IP地址")
|
||||
@Column(name = "ip", length = 15)
|
||||
private String ip;
|
||||
|
||||
@Comment("IP城市地址")
|
||||
@Column(name = "ip_loc", length = 64)
|
||||
private String ipLoc;
|
||||
|
||||
@Comment("点赞数")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "thumbs_up_count", nullable = false)
|
||||
private Integer thumbsUpCount = 0;
|
||||
|
||||
@Comment("点踩数")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "thumbs_down_count", nullable = false)
|
||||
private Integer thumbsDownCount = 0;
|
||||
}
|
93
src/main/java/com/lk/paopao/entity/Post.java
Normal file
93
src/main/java/com/lk/paopao/entity/Post.java
Normal file
@ -0,0 +1,93 @@
|
||||
package com.lk.paopao.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Comment("冒泡/动态/文章")
|
||||
@Entity
|
||||
@Table(name = "p_post", indexes = {
|
||||
@Index(name = "idx_post_user_id", columnList = "user_id"),
|
||||
@Index(name = "idx_post_visibility", columnList = "visibility")
|
||||
})
|
||||
public class Post extends BaseAuditingEntity{
|
||||
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
@Comment("用户ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id")
|
||||
private User user;
|
||||
|
||||
@OneToMany(mappedBy = "post", cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
|
||||
private List<PostContent> contents;
|
||||
|
||||
@Comment("评论数")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "comment_count", nullable = false)
|
||||
private Long commentCount = 0L;
|
||||
|
||||
@Comment("收藏数")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "collection_count", nullable = false)
|
||||
private Long collectionCount = 0L;
|
||||
|
||||
@Comment("点赞数")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "upvote_count", nullable = false)
|
||||
private Long upvoteCount = 0L;
|
||||
|
||||
@Comment("分享数")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "share_count", nullable = false)
|
||||
private Long shareCount = 0L;
|
||||
|
||||
@Comment("可见性: 0私密 10充电可见 20订阅可见 30保留 40保留 50好友可见 60关注可见 70保留 80保留 90公开")
|
||||
@ColumnDefault("50")
|
||||
@Column(name = "visibility", nullable = false)
|
||||
private Byte visibility;
|
||||
|
||||
@Comment("是否置顶")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "is_top", nullable = false)
|
||||
private Boolean isTop = false;
|
||||
|
||||
@Comment("是否精华")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "is_essence", nullable = false)
|
||||
private Boolean isEssence = false;
|
||||
|
||||
@Comment("是否锁定")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "is_lock", nullable = false)
|
||||
private Boolean isLock = false;
|
||||
|
||||
@Comment("最新回复时间")
|
||||
@Column(name = "latest_replied_on")
|
||||
private Long latestRepliedOn = 0L;
|
||||
|
||||
@Comment("参与的主题")
|
||||
@Column(name = "tags")
|
||||
private String tags;
|
||||
|
||||
@Comment("附件价格(分)")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "attachment_price", nullable = false)
|
||||
private Long attachmentPrice = 0L;
|
||||
|
||||
@Comment("IP地址")
|
||||
@Column(name = "ip", length = 15)
|
||||
private String ip;
|
||||
|
||||
@Comment("IP城市地址")
|
||||
@Column(name = "ip_loc", length = 64)
|
||||
private String ipLoc;
|
||||
|
||||
}
|
30
src/main/java/com/lk/paopao/entity/PostCollection.java
Normal file
30
src/main/java/com/lk/paopao/entity/PostCollection.java
Normal file
@ -0,0 +1,30 @@
|
||||
package com.lk.paopao.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Comment("冒泡/文章收藏")
|
||||
@Entity
|
||||
@Table(name = "p_post_collection", indexes = {
|
||||
@Index(name = "idx_post_collection_post_id", columnList = "post_id"),
|
||||
@Index(name = "idx_post_collection_user_id", columnList = "user_id")
|
||||
})
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class PostCollection extends BaseAuditingEntity{
|
||||
|
||||
@Comment("POST ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "post_id", nullable = false)
|
||||
private Post post;
|
||||
|
||||
@Comment("用户ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private User user;
|
||||
|
||||
}
|
41
src/main/java/com/lk/paopao/entity/PostContent.java
Normal file
41
src/main/java/com/lk/paopao/entity/PostContent.java
Normal file
@ -0,0 +1,41 @@
|
||||
package com.lk.paopao.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Comment("冒泡/动态/文章内容")
|
||||
@Entity
|
||||
@Table(name = "p_post_content", indexes = {
|
||||
@Index(name = "idx_post_content_post_id", columnList = "post_id"),
|
||||
@Index(name = "idx_post_content_user_id", columnList = "user_id")
|
||||
})
|
||||
public class PostContent extends BaseAuditingEntity{
|
||||
@Comment("冒泡/动态/文章ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "post_id", nullable = false)
|
||||
private Post post;
|
||||
|
||||
@Comment("用户ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private User user;
|
||||
|
||||
@Comment("内容")
|
||||
@Column(name = "content", nullable = false, length = 4000)
|
||||
private String content;
|
||||
|
||||
@Comment("类型,1标题,2文字段落,3图片地址,4视频地址,5语音地址,6链接地址,7附件资源,8收费资源")
|
||||
@ColumnDefault("2")
|
||||
@Column(name = "type", nullable = false)
|
||||
private Byte type = 2;
|
||||
|
||||
@Comment("排序,越小越靠前")
|
||||
@ColumnDefault("100")
|
||||
@Column(name = "sort", nullable = false)
|
||||
private Integer sort =100;
|
||||
}
|
29
src/main/java/com/lk/paopao/entity/PostStar.java
Normal file
29
src/main/java/com/lk/paopao/entity/PostStar.java
Normal file
@ -0,0 +1,29 @@
|
||||
package com.lk.paopao.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Comment("冒泡/文章点赞")
|
||||
@Entity
|
||||
@Table(name = "p_post_star", indexes = {
|
||||
@Index(name = "idx_post_star_post_id", columnList = "post_id"),
|
||||
@Index(name = "idx_post_star_user_id", columnList = "user_id")
|
||||
})
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class PostStar extends BaseAuditingEntity{
|
||||
|
||||
@Comment("POST ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "post_id", nullable = false)
|
||||
private Post post;
|
||||
|
||||
@Comment("用户ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private User user;
|
||||
}
|
37
src/main/java/com/lk/paopao/entity/Tag.java
Normal file
37
src/main/java/com/lk/paopao/entity/Tag.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.lk.paopao.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
@Getter
|
||||
@Setter
|
||||
@Comment("标签")
|
||||
@Entity
|
||||
@Table(name = "p_tag", indexes = {
|
||||
@Index(name = "idx_tag_user_id", columnList = "user_id"),
|
||||
@Index(name = "idx_tag_quote_num", columnList = "quote_num")
|
||||
}, uniqueConstraints = {
|
||||
@UniqueConstraint(name = "idx_tag_tag", columnNames = {"tag"})
|
||||
})
|
||||
public class Tag extends BaseAuditingEntity{
|
||||
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
@Comment("创建者ID")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private User user;
|
||||
|
||||
@Comment("标签名")
|
||||
@Column(name = "tag", nullable = false)
|
||||
private String tag;
|
||||
|
||||
@Comment("引用数")
|
||||
@ColumnDefault("0")
|
||||
@Column(name = "quote_num", nullable = false)
|
||||
private Long quoteNum = 0L;
|
||||
|
||||
}
|
15
src/main/java/com/lk/paopao/mapper/CommentContentMapper.java
Normal file
15
src/main/java/com/lk/paopao/mapper/CommentContentMapper.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.lk.paopao.mapper;
|
||||
|
||||
import com.lk.paopao.dto.CommentContentDto;
|
||||
import com.lk.paopao.entity.CommentContent;
|
||||
import org.mapstruct.*;
|
||||
|
||||
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
|
||||
public interface CommentContentMapper {
|
||||
CommentContent toEntity(CommentContentDto commentContentDto);
|
||||
|
||||
CommentContentDto toDto(CommentContent commentContent);
|
||||
|
||||
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
|
||||
CommentContent partialUpdate(CommentContentDto commentContentDto, @MappingTarget CommentContent commentContent);
|
||||
}
|
20
src/main/java/com/lk/paopao/mapper/CommentMapper.java
Normal file
20
src/main/java/com/lk/paopao/mapper/CommentMapper.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.lk.paopao.mapper;
|
||||
|
||||
import com.lk.paopao.dto.CommentDto;
|
||||
import com.lk.paopao.entity.Comment;
|
||||
import org.mapstruct.*;
|
||||
|
||||
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
|
||||
public interface CommentMapper {
|
||||
Comment toEntity(CommentDto commentDto);
|
||||
|
||||
@AfterMapping
|
||||
default void linkContents(@MappingTarget Comment comment) {
|
||||
comment.getContents().forEach(content -> content.setComment(comment));
|
||||
}
|
||||
|
||||
CommentDto toDto(Comment comment);
|
||||
|
||||
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
|
||||
Comment partialUpdate(CommentDto commentDto, @MappingTarget Comment comment);
|
||||
}
|
15
src/main/java/com/lk/paopao/mapper/CommentReplyMapper.java
Normal file
15
src/main/java/com/lk/paopao/mapper/CommentReplyMapper.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.lk.paopao.mapper;
|
||||
|
||||
import com.lk.paopao.dto.CommentReplyDto;
|
||||
import com.lk.paopao.entity.CommentReply;
|
||||
import org.mapstruct.*;
|
||||
|
||||
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
|
||||
public interface CommentReplyMapper {
|
||||
CommentReply toEntity(CommentReplyDto commentReplyDto);
|
||||
|
||||
CommentReplyDto toDto(CommentReply commentReply);
|
||||
|
||||
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
|
||||
CommentReply partialUpdate(CommentReplyDto commentReplyDto, @MappingTarget CommentReply commentReply);
|
||||
}
|
15
src/main/java/com/lk/paopao/mapper/PostCollectionMapper.java
Normal file
15
src/main/java/com/lk/paopao/mapper/PostCollectionMapper.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.lk.paopao.mapper;
|
||||
|
||||
import com.lk.paopao.dto.PostCollectionDto;
|
||||
import com.lk.paopao.entity.PostCollection;
|
||||
import org.mapstruct.*;
|
||||
|
||||
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
|
||||
public interface PostCollectionMapper {
|
||||
PostCollection toEntity(PostCollectionDto postCollectionDto);
|
||||
|
||||
PostCollectionDto toDto(PostCollection postCollection);
|
||||
|
||||
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
|
||||
PostCollection partialUpdate(PostCollectionDto postCollectionDto, @MappingTarget PostCollection postCollection);
|
||||
}
|
15
src/main/java/com/lk/paopao/mapper/PostContentMapper.java
Normal file
15
src/main/java/com/lk/paopao/mapper/PostContentMapper.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.lk.paopao.mapper;
|
||||
|
||||
import com.lk.paopao.entity.PostContent;
|
||||
import com.lk.paopao.dto.PostContentDto;
|
||||
import org.mapstruct.*;
|
||||
|
||||
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
|
||||
public interface PostContentMapper {
|
||||
PostContent toEntity(PostContentDto postContentDto);
|
||||
|
||||
PostContentDto toDto(PostContent postContent);
|
||||
|
||||
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
|
||||
PostContent partialUpdate(PostContentDto postContentDto, @MappingTarget PostContent postContent);
|
||||
}
|
15
src/main/java/com/lk/paopao/mapper/PostMapper.java
Normal file
15
src/main/java/com/lk/paopao/mapper/PostMapper.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.lk.paopao.mapper;
|
||||
|
||||
import com.lk.paopao.entity.Post;
|
||||
import com.lk.paopao.dto.PostDto;
|
||||
import org.mapstruct.*;
|
||||
|
||||
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
|
||||
public interface PostMapper {
|
||||
Post toEntity(PostDto postDto);
|
||||
|
||||
PostDto toDto(Post post);
|
||||
|
||||
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
|
||||
Post partialUpdate(PostDto postDto, @MappingTarget Post post);
|
||||
}
|
15
src/main/java/com/lk/paopao/mapper/PostStarMapper.java
Normal file
15
src/main/java/com/lk/paopao/mapper/PostStarMapper.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.lk.paopao.mapper;
|
||||
|
||||
import com.lk.paopao.dto.PostStarDto;
|
||||
import com.lk.paopao.entity.PostStar;
|
||||
import org.mapstruct.*;
|
||||
|
||||
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
|
||||
public interface PostStarMapper {
|
||||
PostStar toEntity(PostStarDto postStarDto);
|
||||
|
||||
PostStarDto toDto(PostStar postStar);
|
||||
|
||||
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
|
||||
PostStar partialUpdate(PostStarDto postStarDto, @MappingTarget PostStar postStar);
|
||||
}
|
17
src/main/java/com/lk/paopao/mapper/TagMapper.java
Normal file
17
src/main/java/com/lk/paopao/mapper/TagMapper.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.lk.paopao.mapper;
|
||||
|
||||
import com.lk.paopao.entity.Tag;
|
||||
import com.lk.paopao.dto.TagDto;
|
||||
import org.mapstruct.*;
|
||||
|
||||
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
|
||||
public interface TagMapper {
|
||||
Tag toEntity(TagDto tagDto);
|
||||
|
||||
@Mapping(source = "user.id", target = "userId")
|
||||
@Mapping(source = "user", target = "user")
|
||||
TagDto toDto(Tag tag);
|
||||
|
||||
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
|
||||
Tag partialUpdate(TagDto tagDto, @MappingTarget Tag tag);
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.lk.paopao.repository;
|
||||
|
||||
import com.lk.paopao.entity.CommentContent;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface CommentContentRepository extends JpaRepository<CommentContent, Long> {
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.lk.paopao.repository;
|
||||
|
||||
import com.lk.paopao.entity.CommentReply;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface CommentReplyRepository extends JpaRepository<CommentReply, Long> {
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.lk.paopao.repository;
|
||||
|
||||
import com.lk.paopao.entity.Comment;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface CommentRepository extends JpaRepository<Comment, Long> {
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.lk.paopao.repository;
|
||||
|
||||
import com.lk.paopao.entity.PostCollection;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PostCollectionRepository extends JpaRepository<PostCollection, Long> {
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.lk.paopao.repository;
|
||||
|
||||
import com.lk.paopao.entity.PostContent;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PostContentRepository extends JpaRepository<PostContent, Long> {
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.lk.paopao.repository;
|
||||
|
||||
import com.lk.paopao.entity.Post;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PostRepository extends JpaRepository<Post, Long> {
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.lk.paopao.repository;
|
||||
|
||||
import com.lk.paopao.entity.PostStar;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PostStarRepository extends JpaRepository<PostStar, Long> {
|
||||
}
|
19
src/main/java/com/lk/paopao/repository/TagRepository.java
Normal file
19
src/main/java/com/lk/paopao/repository/TagRepository.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.lk.paopao.repository;
|
||||
|
||||
import com.lk.paopao.entity.Tag;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface TagRepository extends JpaRepository<Tag, Long> {
|
||||
|
||||
@Query("SELECT t.tag FROM Tag t WHERE t.tag LIKE CONCAT('%', :key, '%') ORDER BY t.tag ASC limit 20")
|
||||
List<String> findByTagContainingOrderByTagAsc(@Param("key") String key);
|
||||
|
||||
Optional<Tag> findByTag(String tag);
|
||||
|
||||
|
||||
}
|
@ -2,9 +2,17 @@ package com.lk.paopao.repository;
|
||||
|
||||
import com.lk.paopao.entity.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
Optional<User> findByUsername(String username);
|
||||
|
||||
// 或者使用@Query注解进行JPQL或SQL查询(如果声明式方法命名无法满足复杂需求)
|
||||
@Query("SELECT u.username FROM User u WHERE u.username LIKE CONCAT('%', :key, '%') ORDER BY u.username ASC limit 20")
|
||||
List<String> findByUsernameContainingOrderByUsernameAsc(@Param("key") String key);
|
||||
|
||||
}
|
@ -25,7 +25,7 @@ spring:
|
||||
defer-datasource-initialization: true
|
||||
database-platform: org.hibernate.dialect.H2Dialect
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
ddl-auto: create-drop
|
||||
# 可选值:create-drop,create,update,none. create-drop:每次启动项目都会删除表,然后重新创建表,适合开发环境;create:每次启动项目都会创建表,适合开发环境;update:每次启动项目都会更新表,适合开发环境;none:不执行任何操作,适合生产环境。
|
||||
properties:
|
||||
hibernate:
|
||||
@ -49,6 +49,8 @@ app:
|
||||
methods: ["GET"]
|
||||
- path: "/v3/**"
|
||||
methods: [ "GET" ]
|
||||
- path: "/h2/**"
|
||||
methods: [ "GET","PUT","POST" ]
|
||||
- path: "/v1/auth/**"
|
||||
methods: [ "GET","PUT","POST"]
|
||||
- path: "/upload/**"
|
||||
|
Loading…
Reference in New Issue
Block a user