forked from woowacourse/jwp-qna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Question.java
81 lines (66 loc) · 1.8 KB
/
Question.java
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
package qna.domain;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
@Entity
public class Question {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Lob
private String contents;
@Column(nullable = false)
private LocalDateTime createdAt;
@Column(nullable = false)
private boolean deleted = false;
@Column(nullable = false, length = 100)
private String title;
private LocalDateTime updatedAt;
private Long writerId;
public Question(String title, String contents) {
this(null, title, contents);
}
public Question(Long id, String title, String contents) {
this.id = id;
this.title = title;
this.contents = contents;
}
public Question() {
}
public Question writeBy(User writer) {
this.writerId = writer.getId();
return this;
}
public boolean isOwner(User writer) {
return this.writerId.equals(writer.getId());
}
public void addAnswer(Answer answer) {
answer.toQuestion(this);
}
public Long getId() {
return id;
}
public Long getWriterId() {
return writerId;
}
public boolean isDeleted() {
return deleted;
}
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}
@Override
public String toString() {
return "Question{" +
"id=" + id +
", title='" + title + '\'' +
", contents='" + contents + '\'' +
", writerId=" + writerId +
", deleted=" + deleted +
'}';
}
}