diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java index ecb1c7c..8132071 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java @@ -16,7 +16,7 @@ public boolean isValid(String value, ConstraintValidatorContext context) { String lowerCasedValue = value.toLowerCase(); - if (value.startsWith(" ") || value.endsWith(" ")) { + if (!value.trim().equals(value)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("name must not start or end with whitespace") .addConstraintViolation(); diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/user/exception/UsernameAlreadyTakenException.java b/src/main/java/org/gelecekbilimde/scienceplatform/user/exception/UsernameAlreadyTakenException.java index a8fea78..1f243c0 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/user/exception/UsernameAlreadyTakenException.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/user/exception/UsernameAlreadyTakenException.java @@ -1,16 +1,16 @@ package org.gelecekbilimde.scienceplatform.user.exception; -import org.gelecekbilimde.scienceplatform.common.exception.AbstractServerException; +import org.gelecekbilimde.scienceplatform.common.exception.AbstractConflictException; import java.io.Serial; -public final class UsernameAlreadyTakenException extends AbstractServerException { +public final class UsernameAlreadyTakenException extends AbstractConflictException { @Serial private static final long serialVersionUID = -3365493595680402581L; public UsernameAlreadyTakenException(String username) { - super(("username is already taken" + username)); + super(String.format("'%s' username already taken", username)); } } diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java b/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java index 2ef1c87..deb1e1a 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java @@ -34,7 +34,7 @@ public class User extends BaseDomainModel { public String getUsername() { - return username.toLowerCase(); + return username != null ? username.toLowerCase() : null; }