-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathPost.java
More file actions
47 lines (38 loc) · 1.07 KB
/
Post.java
File metadata and controls
47 lines (38 loc) · 1.07 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
package com.example.devSns.domain;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import lombok.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Post {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank
@Column(nullable = false)
private String title;
@Lob
private String content;
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<Comment> comments = new ArrayList<>();
@Builder
private Post(String title, String content) {
this.title = title;
this.content = content;
}
public void update(String title, String content) {
this.title = title;
this.content = content;
}
/** 양방향 편의 메서드 */
void addComment(Comment c) {
comments.add(c);
c.setPostInternal(this);
}
void removeComment(Comment c) {
comments.remove(c);
c.setPostInternal(null);
}
}