summaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/blog/web/models/UserEntity.java
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2024-07-20 00:51:37 -0400
committerrealtradam <[email protected]>2024-07-20 00:51:37 -0400
commit5e2eab6f32bc76918aa17791b688d1df27d6ddfc (patch)
tree420a0bcb5091d1e220fa8c42565a507897e11ec4 /src/main/java/com/blog/web/models/UserEntity.java
parenta6a60a5e774eed9d84f522fc452b67ee52e033cb (diff)
downloadspring-blog-5e2eab6f32bc76918aa17791b688d1df27d6ddfc.tar.gz
spring-blog-5e2eab6f32bc76918aa17791b688d1df27d6ddfc.zip
code cleanup
Diffstat (limited to 'src/main/java/com/blog/web/models/UserEntity.java')
-rw-r--r--src/main/java/com/blog/web/models/UserEntity.java21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/main/java/com/blog/web/models/UserEntity.java b/src/main/java/com/blog/web/models/UserEntity.java
index d121580..c94db6b 100644
--- a/src/main/java/com/blog/web/models/UserEntity.java
+++ b/src/main/java/com/blog/web/models/UserEntity.java
@@ -18,25 +18,15 @@ public class UserEntity {
private String email;
private String password;
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
- @JoinTable(
- name = "user_roles",
- joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")},
- inverseJoinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")}
- )
- private List<Role> roles = new ArrayList<>();
+ @JoinTable(name = "user_roles", joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")})
+ private final List<Role> roles = new ArrayList<>();
- public boolean equals(UserEntity user)
- {
+ public boolean equals(UserEntity user) {
return this.id == user.getId();
}
public User toSecurityUser() {
- return new User(
- this.getEmail(),
- this.getPassword(),
- this.getRoles().stream().map((role) -> new SimpleGrantedAuthority(role.getName()))
- .collect(Collectors.toList())
- );
+ return new User(this.getEmail(), this.getPassword(), this.getRoles().stream().map((role) -> new SimpleGrantedAuthority(role.getName())).collect(Collectors.toList()));
}
public Long getId() {
@@ -76,6 +66,7 @@ public class UserEntity {
}
public void setRoles(List<Role> roles) {
- this.roles = roles;
+ this.roles.clear();
+ this.roles.addAll(roles);
}
}