From b7fe16e198d346f1d1880f13c808d0f474c710bd Mon Sep 17 00:00:00 2001 From: LordDangerous Date: Tue, 20 Feb 2024 16:11:01 +0100 Subject: [PATCH 1/4] Added new class Shelter --- EntitiesModel.puml | 2 +- .../udl/eps/softarch/demo/domain/Shelter.java | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java diff --git a/EntitiesModel.puml b/EntitiesModel.puml index 1daee45..4069032 100644 --- a/EntitiesModel.puml +++ b/EntitiesModel.puml @@ -31,7 +31,7 @@ class Cat extends Pet { meowingLevel: Integer } -class Shelter { +class Shelter extends UriEntity{ id: Integer name: String email: String diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java new file mode 100644 index 0000000..9b02a59 --- /dev/null +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java @@ -0,0 +1,44 @@ +package cat.udl.eps.softarch.demo.domain; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import lombok.Data; +import jakarta.persistence.Id; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jdk.jfr.BooleanFlag; +import lombok.EqualsAndHashCode; +import org.hibernate.validator.constraints.Length; + +import java.time.LocalDateTime; + +@Entity +@Data +@EqualsAndHashCode(callSuper = false) +public class Shelter extends UriEntity { + + @Id + private String id; + + @NotBlank + private String name; + + @NotBlank + @Email + @Column(unique = true) + private String email; + + @NotBlank + @Length(min=12, max=12) + private String mobile; + + @NotBlank + private LocalDateTime createdAt; + + @NotBlank + private LocalDateTime updatedAt; + + @BooleanFlag + private boolean isActive; + +} From b9f8bce0d16a6bb14e36728ce4ad3e9f174f2af4 Mon Sep 17 00:00:00 2001 From: LordDangerous Date: Tue, 20 Feb 2024 16:37:14 +0100 Subject: [PATCH 2/4] [FIX] Long ID instead of String --- src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java index 9b02a59..3465ec2 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java @@ -15,10 +15,10 @@ @Entity @Data @EqualsAndHashCode(callSuper = false) -public class Shelter extends UriEntity { +public class Shelter extends UriEntity { @Id - private String id; + private Long id; @NotBlank private String name; From 4b7684903226e8bae2e36ae61c63535a5b0fa71d Mon Sep 17 00:00:00 2001 From: LordDangerous Date: Wed, 28 Feb 2024 17:27:24 +0100 Subject: [PATCH 3/4] FIXED NotBlank to NotNull --- src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java index 3465ec2..8fa75cb 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java @@ -2,6 +2,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.validation.constraints.NotNull; import lombok.Data; import jakarta.persistence.Id; import jakarta.validation.constraints.Email; @@ -32,10 +33,10 @@ public class Shelter extends UriEntity { @Length(min=12, max=12) private String mobile; - @NotBlank + @NotNull private LocalDateTime createdAt; - @NotBlank + @NotNull private LocalDateTime updatedAt; @BooleanFlag From 9a7f0c85a9969dd4307d513b0758d1b70b759952 Mon Sep 17 00:00:00 2001 From: LordDangerous Date: Wed, 28 Feb 2024 17:59:11 +0100 Subject: [PATCH 4/4] Added REGEX to mobile --- src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java index 8fa75cb..2c8eb0d 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java @@ -3,6 +3,7 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; import lombok.Data; import jakarta.persistence.Id; import jakarta.validation.constraints.Email; @@ -30,7 +31,7 @@ public class Shelter extends UriEntity { private String email; @NotBlank - @Length(min=12, max=12) + @Pattern(regexp="(^$|[0-9]{11})") private String mobile; @NotNull