1 package model.entity;
2
3 import lombok.Getter;
4 import lombok.Setter;
5
6 import javax.persistence.*;
7 import java.io.Serializable;
8 import java.time.Instant;
9 import java.util.Map;
10
11
12
13
14 @Entity
15 public class Comment implements Serializable {
16
17 @Setter @Getter
18 @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
19 protected Integer id;
20
21 @Setter @Getter
22 @ManyToOne(fetch = FetchType.LAZY, optional = false)
23 protected Post post;
24
25 @Setter @Getter
26 @ManyToOne(fetch = FetchType.LAZY, optional = false)
27 protected User author;
28
29
30
31
32 @Setter @Getter
33 @ManyToOne(fetch = FetchType.LAZY, optional = true)
34 protected Comment parentComment;
35
36 @Setter @Getter
37 @Column(columnDefinition = "TEXT", nullable = false)
38 protected String content;
39
40 @Getter
41 @Column(nullable = false, updatable = false, insertable = false)
42 protected Instant creationDate;
43
44 @Getter
45 @Column(name="votes", insertable = false, updatable = false)
46 protected Integer votesCount;
47
48
49
50
51
52 @Getter
53 @Column(insertable = false, updatable = false)
54 protected String path;
55
56 @OneToMany(mappedBy="comment")
57 @MapKeyJoinColumn(name="user_id", updatable = false, insertable = false)
58 protected Map<User, CommentVote> votes;
59
60
61
62
63
64
65 public CommentVote getVote(User user){
66 return votes.get(user);
67 }
68
69 public Comment(){}
70
71 @Override
72 public boolean equals(Object o) {
73 if (this == o) return true;
74 if (!(o instanceof Comment)) return false;
75 Comment comment = (Comment) o;
76 return id.equals(comment.id);
77 }
78
79 @Override
80 public int hashCode() {
81 return getClass().hashCode();
82 }
83 }