Commit de1efd0b authored by Alex Segers's avatar Alex Segers

[AFP-91] 🐛 Fix validations & error messages in 'Manager' model (@asegers)

parent 7a746815
......@@ -4,12 +4,10 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.URL;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import javax.validation.constraints.*;
import java.lang.reflect.Field;
import static java.util.Objects.isNull;
@Data
@NoArgsConstructor
......@@ -18,30 +16,18 @@ public class Manager {
@Id
private String id;
@Size(min = 1, max = 250, message = "'firstName' must be between 1 & 250 characters")
@NotNull
@Size(min = 1, max = 250)
@NotNull()
private String firstName, lastName;
@Indexed(unique = true)
@Email
private String email;
@NotNull
@Size(min = 21, max = 21, message = "'googleId' is invalid")
@Size(min = 21, max = 21)
@NotNull()
private String googleId;
@URL(message = "'imageUrl' must be a valid URL")
@URL
private String imageUrl;
static public Manager combine(Manager target, Manager source) {
try {
for (Field field: Manager.class.getDeclaredFields()) {
String fieldName = field.getName();
Object sourceValue = field.get(source);
if (!isNull(sourceValue) && !fieldName.equals("id"))
field.set(target, sourceValue);
}
} catch (Exception ignore) { }
return target;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment