Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package bg.softuni.invoice.model.bind;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import static bg.softuni.invoice.constant.ErrorMsg.EMAIL_NOT_CORRECT;
import static bg.softuni.invoice.constant.ErrorMsg.EMAIL_NOT_EMPTY;
import static bg.softuni.invoice.constant.ErrorMsg.EMAIL_REGEX;

@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class UserBaseBindingModel {

@NotBlank(message = EMAIL_NOT_EMPTY)
@Pattern(regexp = EMAIL_REGEX, message = EMAIL_NOT_CORRECT)
private String username;

}
33 changes: 33 additions & 0 deletions src/main/java/bg/softuni/invoice/model/bind/UserBindingModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package bg.softuni.invoice.model.bind;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

import static bg.softuni.invoice.constant.ErrorMsg.FIRST_NAME_FIRST_LETTER_UPPERCASE;
import static bg.softuni.invoice.constant.ErrorMsg.FIRST_NAME_MIN_LENGTH;
import static bg.softuni.invoice.constant.ErrorMsg.LAST_NAME_FIRST_LETTER_UPPERCASE;
import static bg.softuni.invoice.constant.ErrorMsg.LAST_NAME_MIN_LENGTH;
import static bg.softuni.invoice.constant.ErrorMsg.NAME_REGEX;
import static bg.softuni.invoice.constant.ErrorMsg.STRING_MIN_LENGTH;

@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class UserBindingModel extends UserBaseBindingModel {

@NotEmpty(message = FIRST_NAME_MIN_LENGTH)
@Length(min = STRING_MIN_LENGTH, message = FIRST_NAME_MIN_LENGTH)
@Pattern(regexp = NAME_REGEX, message = FIRST_NAME_FIRST_LETTER_UPPERCASE)
private String firstName;

@NotEmpty(message = LAST_NAME_MIN_LENGTH)
@Length(min = STRING_MIN_LENGTH, message = LAST_NAME_MIN_LENGTH)
@Pattern(regexp = NAME_REGEX, message = LAST_NAME_FIRST_LETTER_UPPERCASE)
private String lastName;

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
package bg.softuni.invoice.model.bind;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;

import static bg.softuni.invoice.constant.ErrorMsg.EMAIL_NOT_CORRECT;
import static bg.softuni.invoice.constant.ErrorMsg.EMAIL_NOT_EMPTY;
import static bg.softuni.invoice.constant.ErrorMsg.EMAIL_REGEX;
import static bg.softuni.invoice.constant.ErrorMsg.PASSWORD_NOT_EMPTY;

@Setter
@Getter
public class UserLoginBindingModel {

@NotBlank(message = EMAIL_NOT_EMPTY)
@Pattern(regexp = EMAIL_REGEX,
message = EMAIL_NOT_CORRECT)
private String username;
public class UserLoginBindingModel extends UserBaseBindingModel {

@NotBlank(message = PASSWORD_NOT_EMPTY)
private String password;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
package bg.softuni.invoice.model.bind;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

import static bg.softuni.invoice.constant.ErrorMsg.EMAIL_NOT_CORRECT;
import static bg.softuni.invoice.constant.ErrorMsg.EMAIL_NOT_EMPTY;
import static bg.softuni.invoice.constant.ErrorMsg.EMAIL_REGEX;
import static bg.softuni.invoice.constant.ErrorMsg.FIRST_NAME_FIRST_LETTER_UPPERCASE;
import static bg.softuni.invoice.constant.ErrorMsg.FIRST_NAME_MIN_LENGTH;
import static bg.softuni.invoice.constant.ErrorMsg.LAST_NAME_FIRST_LETTER_UPPERCASE;
import static bg.softuni.invoice.constant.ErrorMsg.LAST_NAME_MIN_LENGTH;
import static bg.softuni.invoice.constant.ErrorMsg.NAME_REGEX;
import static bg.softuni.invoice.constant.ErrorMsg.STRING_MIN_LENGTH;

@Setter
@Getter
public class UserProfileBindingModel {
public class UserProfileBindingModel extends UserBindingModel {

private String id;

@NotEmpty(message = EMAIL_NOT_EMPTY)
@Pattern(regexp = EMAIL_REGEX, message = EMAIL_NOT_CORRECT)
private String username;

@NotEmpty(message = FIRST_NAME_MIN_LENGTH)
@Length(min = STRING_MIN_LENGTH, message = FIRST_NAME_MIN_LENGTH)
@Pattern(regexp = NAME_REGEX, message = FIRST_NAME_FIRST_LETTER_UPPERCASE)
private String firstName;

@NotEmpty(message = LAST_NAME_MIN_LENGTH)
@Length(min = STRING_MIN_LENGTH, message = LAST_NAME_MIN_LENGTH)
@Pattern(regexp = NAME_REGEX, message = LAST_NAME_FIRST_LETTER_UPPERCASE)
private String lastName;

}
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
package bg.softuni.invoice.model.bind;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;

import static bg.softuni.invoice.constant.ErrorMsg.EMAIL_NOT_CORRECT;
import static bg.softuni.invoice.constant.ErrorMsg.EMAIL_NOT_EMPTY;
import static bg.softuni.invoice.constant.ErrorMsg.EMAIL_REGEX;
import static bg.softuni.invoice.constant.ErrorMsg.FIRST_NAME_FIRST_LETTER_UPPERCASE;
import static bg.softuni.invoice.constant.ErrorMsg.FIRST_NAME_MIN_LENGTH;
import static bg.softuni.invoice.constant.ErrorMsg.LAST_NAME_FIRST_LETTER_UPPERCASE;
import static bg.softuni.invoice.constant.ErrorMsg.LAST_NAME_MIN_LENGTH;
import static bg.softuni.invoice.constant.ErrorMsg.NAME_REGEX;
import static bg.softuni.invoice.constant.ErrorMsg.PASSWORD_MIN_LENGTH;
import static bg.softuni.invoice.constant.ErrorMsg.PASSWORD_NOT_EMPTY;
import static bg.softuni.invoice.constant.ErrorMsg.STRING_MIN_LENGTH;

@Setter
@Getter
public class UserRegisterBindingModel {

@NotEmpty(message = EMAIL_NOT_EMPTY)
@Pattern(regexp = EMAIL_REGEX, message = EMAIL_NOT_CORRECT)
private String username;

@NotEmpty(message = FIRST_NAME_MIN_LENGTH)
@Length(min = STRING_MIN_LENGTH, message = FIRST_NAME_MIN_LENGTH)
@Pattern(regexp = NAME_REGEX, message = FIRST_NAME_FIRST_LETTER_UPPERCASE)
private String firstName;

@NotEmpty(message = LAST_NAME_MIN_LENGTH)
@Length(min = STRING_MIN_LENGTH, message = LAST_NAME_MIN_LENGTH)
@Pattern(regexp = NAME_REGEX, message = LAST_NAME_FIRST_LETTER_UPPERCASE)
private String lastName;
public class UserRegisterBindingModel extends UserBindingModel {

@NotEmpty(message = PASSWORD_NOT_EMPTY)
@Length(min = STRING_MIN_LENGTH, message = PASSWORD_MIN_LENGTH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void username_withValidValues_shouldPassValidation(String validUsername) {

@ParameterizedTest
@CsvSource({
"' '",
"@",
"plain@",
"email.com"
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void username_withValidValues_shouldPassValidation(String validUsername) {

@ParameterizedTest
@CsvSource({
"' '",
"@",
"invalid@",
"plainaddress"
})
Expand Down