From 4976d687fc2dce7012e3f04f8a15b61ae6345b79 Mon Sep 17 00:00:00 2001 From: Sebastian Jitaru Date: Thu, 7 Mar 2024 16:01:19 +0100 Subject: [PATCH 1/3] Made find by name return Shelter not list --- .../udl/eps/softarch/demo/repository/ShelterRepository.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterRepository.java index 631219ae..9519769c 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterRepository.java +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterRepository.java @@ -12,5 +12,6 @@ @RepositoryRestResource public interface ShelterRepository extends CrudRepository, PagingAndSortingRepository { - List findByName(@Param("name") String name); + Shelter findByName(@Param("name") String name); + List findByLocatedAt(@Param("location") Location location); } \ No newline at end of file From ea00b32e92bd02a39bb3aff7e20c55a0eda36c7b Mon Sep 17 00:00:00 2001 From: Sebastian Jitaru Date: Thu, 7 Mar 2024 16:35:44 +0100 Subject: [PATCH 2/3] Added PrePersist on times --- .../java/cat/udl/eps/softarch/demo/domain/Shelter.java | 9 ++++++--- .../eps/softarch/demo/repository/ShelterRepository.java | 2 +- 2 files changed, 7 insertions(+), 4 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 7fdaaf46..10fe7d19 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 @@ -24,7 +24,6 @@ public class Shelter extends UriEntity { private Long id; @NotBlank - @Column(unique = true) private String name; @NotBlank @@ -37,12 +36,10 @@ public class Shelter extends UriEntity { private String mobile; @PastOrPresent - @GeneratedValue(strategy = GenerationType.AUTO) @NotNull private ZonedDateTime createdAt; @PastOrPresent - @GeneratedValue(strategy = GenerationType.AUTO) private ZonedDateTime updatedAt; @NotNull @@ -52,4 +49,10 @@ public class Shelter extends UriEntity { @OneToOne public Location locatedAt; + + @PrePersist + public void prePersist() { + createdAt = ZonedDateTime.now(); + updatedAt = ZonedDateTime.now(); + } } \ No newline at end of file diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterRepository.java index 9519769c..04b828d8 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterRepository.java +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterRepository.java @@ -12,6 +12,6 @@ @RepositoryRestResource public interface ShelterRepository extends CrudRepository, PagingAndSortingRepository { - Shelter findByName(@Param("name") String name); + List findByName(@Param("name") String name); List findByLocatedAt(@Param("location") Location location); } \ No newline at end of file From b3aa1aeb2568c6fd84741b46d5b04a99a0a39777 Mon Sep 17 00:00:00 2001 From: Sebastian Jitaru Date: Thu, 7 Mar 2024 16:43:39 +0100 Subject: [PATCH 3/3] isActive initialized to false and made persistent --- src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java | 1 + 1 file changed, 1 insertion(+) 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 10fe7d19..172379c9 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 @@ -54,5 +54,6 @@ public class Shelter extends UriEntity { public void prePersist() { createdAt = ZonedDateTime.now(); updatedAt = ZonedDateTime.now(); + isActive = false; } } \ No newline at end of file