Skip to content

Commit 52b4d59

Browse files
committed
Delete boilerplate code from User
1 parent 21e5bf2 commit 52b4d59

File tree

1 file changed

+16
-43
lines changed
  • src/main/java/com/bezkoder/springjwt/models

1 file changed

+16
-43
lines changed
Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.bezkoder.springjwt.models;
22

3+
import lombok.Getter;
4+
import lombok.NoArgsConstructor;
5+
import lombok.Setter;
6+
37
import java.util.HashSet;
48
import java.util.Set;
59

@@ -8,13 +12,17 @@
812
import javax.validation.constraints.NotBlank;
913
import javax.validation.constraints.Size;
1014

15+
@Getter
16+
@Setter
17+
@NoArgsConstructor // JPA requires that this constructor be defined as public or protected
1118
@Entity
1219
@Table(name = "users",
1320
uniqueConstraints = {
1421
@UniqueConstraint(columnNames = "username"),
1522
@UniqueConstraint(columnNames = "email")
1623
})
1724
public class User {
25+
// == fields ==
1826
@Id
1927
@GeneratedValue(strategy = GenerationType.IDENTITY)
2028
private Long id;
@@ -32,58 +40,23 @@ public class User {
3240
@Size(max = 120)
3341
private String password;
3442

43+
// == relationships ==
3544
@ManyToMany(fetch = FetchType.LAZY)
3645
@JoinTable( name = "user_roles",
3746
joinColumns = @JoinColumn(name = "user_id"),
3847
inverseJoinColumns = @JoinColumn(name = "role_id"))
3948
private Set<Role> roles = new HashSet<>();
4049

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+
*/
4457
public User(String username, String email, String password) {
4558
this.username = username;
4659
this.email = email;
4760
this.password = password;
4861
}
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-
}
8962
}

0 commit comments

Comments
 (0)