Add fields to user entity.
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
}
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ import java.util.UUID;
|
||||
|
||||
public record User(
|
||||
UUID id,
|
||||
String pseudo,
|
||||
String email,
|
||||
String password,
|
||||
UUID photoId,
|
||||
List<UserRole> roles
|
||||
) {}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -21,4 +21,6 @@ public interface UserPort {
|
||||
Optional<RefreshToken> findRefreshTokenById(UUID refreshTokenId);
|
||||
|
||||
void save(RefreshToken refreshToken);
|
||||
|
||||
boolean existsByEmail(String email);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user