forked from solid-connection/solid-connect-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPost.java
More file actions
88 lines (70 loc) · 2.7 KB
/
Post.java
File metadata and controls
88 lines (70 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.example.solidconnection.community.post.domain;
import com.example.solidconnection.common.BaseEntity;
import com.example.solidconnection.community.comment.domain.Comment;
import com.example.solidconnection.community.post.dto.PostUpdateRequest;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Where;
@Entity
@Getter
@NoArgsConstructor
@EqualsAndHashCode(of = "id")
@Where(clause = "is_deleted = false")
public class Post extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(length = 255)
private String title;
@Column(length = 1000)
private String content;
private Boolean isQuestion;
private Long likeCount;
private Long viewCount;
@Enumerated(EnumType.STRING)
private PostCategory category;
@Column
private String boardCode;
@Column
private long siteUserId;
@Column(name = "is_deleted", columnDefinition = "boolean default false", nullable = false)
private boolean isDeleted = false;
@BatchSize(size = 20)
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Comment> commentList = new ArrayList<>();
@BatchSize(size = 5)
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true)
private List<PostImage> postImageList = new ArrayList<>();
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true)
private List<PostLike> postLikeList = new ArrayList<>();
public Post(String title, String content, Boolean isQuestion, Long likeCount, Long viewCount, PostCategory category) {
this.title = title;
this.content = content;
this.isQuestion = isQuestion;
this.likeCount = likeCount;
this.viewCount = viewCount;
this.category = category;
}
public void setBoardAndSiteUserId(String boardCode, long siteUserId) {
this.boardCode = boardCode;
this.siteUserId = siteUserId;
}
public void update(PostUpdateRequest postUpdateRequest) {
this.title = postUpdateRequest.title();
this.content = postUpdateRequest.content();
this.category = PostCategory.valueOf(postUpdateRequest.postCategory());
}
}