1
1
package com .bezkoder .springjwt .models ;
2
2
3
+ import lombok .Getter ;
4
+ import lombok .NoArgsConstructor ;
5
+ import lombok .Setter ;
6
+
3
7
import java .util .HashSet ;
4
8
import java .util .Set ;
5
9
8
12
import javax .validation .constraints .NotBlank ;
9
13
import javax .validation .constraints .Size ;
10
14
15
+ @ Getter
16
+ @ Setter
17
+ @ NoArgsConstructor // JPA requires that this constructor be defined as public or protected
11
18
@ Entity
12
19
@ Table (name = "users" ,
13
20
uniqueConstraints = {
14
21
@ UniqueConstraint (columnNames = "username" ),
15
22
@ UniqueConstraint (columnNames = "email" )
16
23
})
17
24
public class User {
25
+ // == fields ==
18
26
@ Id
19
27
@ GeneratedValue (strategy = GenerationType .IDENTITY )
20
28
private Long id ;
@@ -32,58 +40,23 @@ public class User {
32
40
@ Size (max = 120 )
33
41
private String password ;
34
42
43
+ // == relationships ==
35
44
@ ManyToMany (fetch = FetchType .LAZY )
36
45
@ JoinTable ( name = "user_roles" ,
37
46
joinColumns = @ JoinColumn (name = "user_id" ),
38
47
inverseJoinColumns = @ JoinColumn (name = "role_id" ))
39
48
private Set <Role > roles = new HashSet <>();
40
49
41
- public User () {
42
- }
43
-
50
+ // == constructors ==
51
+ /**
52
+ * Constructs an {@code User} object initialized with the given values.
53
+ * @param username the username of the user
54
+ * @param email the email of the user
55
+ * @param password the password of the user
56
+ */
44
57
public User (String username , String email , String password ) {
45
58
this .username = username ;
46
59
this .email = email ;
47
60
this .password = password ;
48
61
}
49
-
50
- public Long getId () {
51
- return id ;
52
- }
53
-
54
- public void setId (Long id ) {
55
- this .id = id ;
56
- }
57
-
58
- public String getUsername () {
59
- return username ;
60
- }
61
-
62
- public void setUsername (String username ) {
63
- this .username = username ;
64
- }
65
-
66
- public String getEmail () {
67
- return email ;
68
- }
69
-
70
- public void setEmail (String email ) {
71
- this .email = email ;
72
- }
73
-
74
- public String getPassword () {
75
- return password ;
76
- }
77
-
78
- public void setPassword (String password ) {
79
- this .password = password ;
80
- }
81
-
82
- public Set <Role > getRoles () {
83
- return roles ;
84
- }
85
-
86
- public void setRoles (Set <Role > roles ) {
87
- this .roles = roles ;
88
- }
89
62
}
0 commit comments