summaryrefslogtreecommitdiffhomepage
path: root/backend/src/main/java/com/blog/web/models/UserEntity.java
diff options
context:
space:
mode:
Diffstat (limited to 'backend/src/main/java/com/blog/web/models/UserEntity.java')
-rw-r--r--backend/src/main/java/com/blog/web/models/UserEntity.java22
1 files changed, 9 insertions, 13 deletions
diff --git a/backend/src/main/java/com/blog/web/models/UserEntity.java b/backend/src/main/java/com/blog/web/models/UserEntity.java
index 089b8bc..f74308b 100644
--- a/backend/src/main/java/com/blog/web/models/UserEntity.java
+++ b/backend/src/main/java/com/blog/web/models/UserEntity.java
@@ -1,12 +1,11 @@
package com.blog.web.models;
import jakarta.persistence.*;
+import jakarta.validation.constraints.NotEmpty;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
-import java.util.ArrayList;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -15,13 +14,18 @@ import java.util.stream.Collectors;
public class UserEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
- private long id;
+ private final long id = 0;
+ @NotEmpty
+ @Column(unique = true)
private String username;
+ @NotEmpty
+ @Column(unique = true)
private String email;
+ @NotEmpty
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 Set<Role> roles = new HashSet<>();
+ private final Set<Role> roles = new HashSet<>();
public UserEntity(String username, String email, String password, HashSet<Role> roles) {
this.username = username;
@@ -39,17 +43,13 @@ public class UserEntity {
}
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.password, this.getRoles().stream().map((role) -> new SimpleGrantedAuthority(role.getName())).collect(Collectors.toList()));
}
public long getId() {
return id;
}
- public void setId(long id) {
- this.id = id;
- }
-
public String getUsername() {
return username;
}
@@ -66,10 +66,6 @@ public class UserEntity {
this.email = email;
}
- public String getPassword() {
- return password;
- }
-
public void setPassword(String password) {
this.password = password;
}