-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathComment.java
More file actions
46 lines (37 loc) · 1.06 KB
/
Comment.java
File metadata and controls
46 lines (37 loc) · 1.06 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
package com.example.devSns.domain;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import lombok.*;
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Comment {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank
@Column(nullable = false)
private String content;
/** 어느 Post 에 달린 댓글인지 */
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private Post post;
/** 누가 쓴 댓글인지 */
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member author;
@Builder
private Comment(String content, Post post, Member author) {
this.content = content;
this.post = post;
this.author = author;
}
public void update(String content) {
this.content = content;
}
void setPostInternal(Post post) {
this.post = post;
}
public void changeAuthor(Member author) {
this.author = author;
}
}