add validation
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
@@ -24,9 +30,14 @@ public class Expense implements IMoneyTransaction {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "category_id")
|
||||
@NotNull
|
||||
private ExpenseCategory category;
|
||||
|
||||
@NotNull
|
||||
private LocalDate date;
|
||||
|
||||
@NotNull
|
||||
@DecimalMin(value = "0.0", inclusive = false)
|
||||
private BigDecimal amount;
|
||||
|
||||
public Expense(LocalDate date, BigDecimal amount) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@@ -12,5 +14,7 @@ public class ExpenseCategory implements IMoneyTransactionCategory {
|
||||
private Long id;
|
||||
|
||||
@Column(name = "category_name")
|
||||
@NotNull(message = "Name must not be null")
|
||||
@NotEmpty(message = "Name must not be empty")
|
||||
private String name;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -25,9 +27,14 @@ public class Income implements IMoneyTransaction {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "category_id")
|
||||
@NotNull
|
||||
private IncomeCategory category;
|
||||
|
||||
@NotNull
|
||||
private LocalDate date;
|
||||
|
||||
@NotNull
|
||||
@DecimalMin(value = "0.0", inclusive = false)
|
||||
private BigDecimal amount;
|
||||
|
||||
public Income(IncomeCategory incomeCategory, LocalDate date, BigDecimal amount) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@@ -12,6 +14,8 @@ public class IncomeCategory implements IMoneyTransactionCategory {
|
||||
private Long id;
|
||||
|
||||
@Column(name = "category_name")
|
||||
@NotNull(message = "Name must not be null")
|
||||
@NotEmpty(message = "Name must not be empty")
|
||||
private String name;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -17,15 +19,23 @@ public class User {
|
||||
private String userUuid;
|
||||
|
||||
@Column(name = "name")
|
||||
@NotNull(message = "First name must not be null")
|
||||
@NotEmpty(message = "First name must not be empty")
|
||||
private String firstName;
|
||||
|
||||
@Column(name = "surname")
|
||||
@NotNull(message = "Last name must not be null")
|
||||
@NotEmpty(message = "Last name must not be empty")
|
||||
private String lastName;
|
||||
|
||||
@Column(name = "username")
|
||||
@NotNull(message = "Username must not be null")
|
||||
@NotEmpty(message = "Username must not be empty")
|
||||
private String username;
|
||||
|
||||
@Transient
|
||||
@NotNull(message = "Password must not be null")
|
||||
@NotEmpty(message = "Password must not be empty")
|
||||
private String password;
|
||||
|
||||
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
|
||||
|
||||
Reference in New Issue
Block a user