-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBoard.java
More file actions
49 lines (39 loc) · 1.36 KB
/
Board.java
File metadata and controls
49 lines (39 loc) · 1.36 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
package com.example.jpa.board.domain;
import com.example.jpa.board.dto.request.BoardUpdateRequest;
import com.example.jpa.member.domain.Member;
import com.example.jpa.reply.domain.Reply;
import jakarta.persistence.*;
import lombok.*;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Board {
// @Builder - 생성자를 통해 반환하기 때문에 필요 X
// @Setter - update 메서드를 통해 수정하기 때문에 필요 X
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "board_id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member writer;
@OneToMany(mappedBy = "board", orphanRemoval = true)
private List<Reply> replyList = new ArrayList<>();
private String title;
private String content;
private LocalDate date;
@Builder
public Board(Member writer, String title, String content, LocalDate date) {
this.writer = writer;
this.title = title;
this.content = content;
this.date = date;
}
public void update(BoardUpdateRequest boardUpdateRequest) {
this.title = boardUpdateRequest.getTitle();
this.content = boardUpdateRequest.getContent();
this.date = LocalDate.now();
}
}