1 package model.entity;
2
3 import lombok.Getter;
4 import lombok.Setter;
5 import org.hibernate.annotations.NaturalId;
6
7 import javax.persistence.*;
8 import java.io.Serializable;
9 import java.time.Instant;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13
14
15
16
17 @Entity
18 public class User implements Serializable {
19
20 @Getter @Setter
21 @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
22 protected Integer id;
23
24 @Getter @Setter
25 @NaturalId(mutable = false) @Column(length = 30, unique = true, nullable = false)
26 protected String username;
27
28 @Getter @Setter
29 @Column(length = 16, nullable = false)
30 protected byte[] password;
31
32 @Getter @Setter
33 @Column(length = 16, nullable = false)
34 protected byte[] salt;
35
36 @Getter @Setter
37 @Column(length = 255, unique = true, nullable = false)
38 protected String email;
39
40 @Getter @Setter
41 @Column(length = 255)
42 protected String description;
43
44 @Getter @Setter
45 @Column(length = 4096)
46 protected String picture;
47
48 @Getter
49 @Column(insertable = false, updatable = false, nullable = false)
50 protected Instant creationDate;
51
52 @Getter @Setter
53 @Column(nullable = false)
54 protected Boolean admin;
55
56 @OneToMany(mappedBy = "user")
57 @OrderBy("endTime desc")
58 protected List<Ban> bans = new ArrayList<>();
59 public List<Ban> getBans(){
60 return Collections.unmodifiableList(bans);
61 }
62
63 public User(){}
64
65 @Override
66 public boolean equals(Object o) {
67 if (this == o) return true;
68 if (!(o instanceof User)) return false;
69 User user = (User) o;
70 return id.equals(user.id);
71 }
72
73 @Override
74 public int hashCode() {
75 return getClass().hashCode();
76 }
77 }