Add fields to user entity.

This commit is contained in:
Florian THIERRY
2024-03-14 18:17:03 +01:00
parent 9fcfc04117
commit 50b305c3cd
14 changed files with 174 additions and 4 deletions

View File

@@ -0,0 +1,9 @@
package org.codiki.domain.user.exception;
import org.codiki.domain.exception.FunctionnalException;
public class UserAlreadyExistsException extends FunctionnalException {
public UserAlreadyExistsException() {
super("An user already exists with this email address.");
}
}

View File

@@ -0,0 +1,9 @@
package org.codiki.domain.user.exception;
import org.codiki.domain.exception.FunctionnalException;
public class UserCreationException extends FunctionnalException {
public UserCreationException() {
super("Pseudo, email address and password can not be empty.");
}
}

View File

@@ -5,6 +5,9 @@ import java.util.UUID;
public record User(
UUID id,
String pseudo,
String email,
String password,
UUID photoId,
List<UserRole> roles
) {}

View File

@@ -0,0 +1,64 @@
package org.codiki.domain.user.model.builder;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.codiki.domain.user.model.User;
import org.codiki.domain.user.model.UserRole;
public class UserBuilder {
private UUID id;
private String pseudo;
private String email;
private String password;
private UUID photoId;
private Set<UserRole> roles = new HashSet<>();
private UserBuilder() {}
public static UserBuilder anUser() {
return new UserBuilder();
}
public UserBuilder withId(UUID id) {
this.id = id;
return this;
}
public UserBuilder withPseudo(String pseudo) {
this.pseudo = pseudo;
return this;
}
public UserBuilder withEmail(String email) {
this.email = email;
return this;
}
public UserBuilder withPassword(String password) {
this.password = password;
return this;
}
public UserBuilder withPhotoId(UUID photoId) {
this.photoId = photoId;
return this;
}
public UserBuilder withRole(UserRole role) {
this.roles.add(role);
return this;
}
public UserBuilder withRoles(List<UserRole> roles) {
this.roles = new HashSet<>(roles);
return this;
}
public User build() {
return new User(id, pseudo,email, password, photoId, new LinkedList<>(roles));
}
}

View File

@@ -21,4 +21,6 @@ public interface UserPort {
Optional<RefreshToken> findRefreshTokenById(UUID refreshTokenId);
void save(RefreshToken refreshToken);
boolean existsByEmail(String email);
}