From a255eefc7a61e6f850bccfe05a2f1c31df186229 Mon Sep 17 00:00:00 2001 From: Ant Date: Wed, 13 Mar 2024 17:41:09 +0100 Subject: [PATCH 1/9] created Favourite endpoint for the ManyToMany "favouritedBy" relation --- .../eps/softarch/demo/domain/Favourite.java | 26 +++++++++++++++++++ .../demo/repository/FavouriteRepository.java | 8 ++++++ 2 files changed, 34 insertions(+) create mode 100644 src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java create mode 100644 src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java new file mode 100644 index 00000000..0f85bf3d --- /dev/null +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java @@ -0,0 +1,26 @@ +package cat.udl.eps.softarch.demo.domain; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.data.annotation.Id; + +@EqualsAndHashCode(callSuper = true) +@Entity +@Data +public class Favourite extends UriEntity{ + @Id + @GeneratedValue + Long id; + + @ManyToOne + @JoinColumn(name = "pet_id") + Pet pet; + + @ManyToOne + @JoinColumn(name = "user_id") + User user; +} diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java new file mode 100644 index 00000000..996a5600 --- /dev/null +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java @@ -0,0 +1,8 @@ +package cat.udl.eps.softarch.demo.repository; + +import cat.udl.eps.softarch.demo.domain.Favourite; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.PagingAndSortingRepository; + +public interface FavouriteRepository extends CrudRepository, PagingAndSortingRepository { +} From bfcfa25e93435435c54198a1698ba5010cf3baec Mon Sep 17 00:00:00 2001 From: Ant Date: Wed, 13 Mar 2024 17:41:09 +0100 Subject: [PATCH 2/9] created Favourite endpoint for the ManyToMany "favouritedBy" relation --- .../eps/softarch/demo/domain/Favourite.java | 26 +++++++++++++++++++ .../demo/repository/FavouriteRepository.java | 8 ++++++ 2 files changed, 34 insertions(+) create mode 100644 src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java create mode 100644 src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java new file mode 100644 index 00000000..7dd7ad60 --- /dev/null +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java @@ -0,0 +1,26 @@ +package cat.udl.eps.softarch.demo.domain; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.data.annotation.Id; + +@EqualsAndHashCode(callSuper = true) +@Entity +@Data +public class Favourite extends UriEntity{ + @Id + @GeneratedValue + Long id; + + @ManyToOne + @JoinColumn(name = "id") + Pet pet; + + @ManyToOne + @JoinColumn(name = "id") + User user; +} diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java new file mode 100644 index 00000000..996a5600 --- /dev/null +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java @@ -0,0 +1,8 @@ +package cat.udl.eps.softarch.demo.repository; + +import cat.udl.eps.softarch.demo.domain.Favourite; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.PagingAndSortingRepository; + +public interface FavouriteRepository extends CrudRepository, PagingAndSortingRepository { +} From af40c7e3ad3d1fc531e671e40751dd101bdd8d4e Mon Sep 17 00:00:00 2001 From: Antt02 Date: Tue, 19 Mar 2024 19:38:24 +0100 Subject: [PATCH 3/9] checking if failure comes from pushing repository and base class at the same time --- .../demo/repository/FavouriteRepository.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java index 996a5600..2e0e5da3 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java @@ -1,8 +1,8 @@ -package cat.udl.eps.softarch.demo.repository; +//package cat.udl.eps.softarch.demo.repository; -import cat.udl.eps.softarch.demo.domain.Favourite; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; +//import cat.udl.eps.softarch.demo.domain.Favourite; +//import org.springframework.data.repository.CrudRepository; +//import org.springframework.data.repository.PagingAndSortingRepository; -public interface FavouriteRepository extends CrudRepository, PagingAndSortingRepository { -} +//public interface FavouriteRepository extends CrudRepository, PagingAndSortingRepository { +//} From 7467bb018e04d42c1dc9767427ce7b35807c479c Mon Sep 17 00:00:00 2001 From: Antt02 Date: Tue, 19 Mar 2024 19:38:24 +0100 Subject: [PATCH 4/9] checking if failure comes from pushing repository and base class at the same time --- .../eps/softarch/demo/repository/FavouriteRepository.java | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java deleted file mode 100644 index 996a5600..00000000 --- a/src/main/java/cat/udl/eps/softarch/demo/repository/FavouriteRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package cat.udl.eps.softarch.demo.repository; - -import cat.udl.eps.softarch.demo.domain.Favourite; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; - -public interface FavouriteRepository extends CrudRepository, PagingAndSortingRepository { -} From 13f10a7348cf86d4dbdd122c8cbf205e10ab1bad Mon Sep 17 00:00:00 2001 From: Antt02 Date: Tue, 19 Mar 2024 19:45:35 +0100 Subject: [PATCH 5/9] fixing favourite implementation --- src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java index 7dd7ad60..9eb740be 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java @@ -17,10 +17,8 @@ public class Favourite extends UriEntity{ Long id; @ManyToOne - @JoinColumn(name = "id") Pet pet; @ManyToOne - @JoinColumn(name = "id") User user; } From d40a3c40140c7df5baf2369ead7d49928203612e Mon Sep 17 00:00:00 2001 From: Antt02 Date: Tue, 19 Mar 2024 19:45:35 +0100 Subject: [PATCH 6/9] fixing favourite implementation --- src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java index 7dd7ad60..fec65d1b 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java @@ -12,15 +12,13 @@ @Entity @Data public class Favourite extends UriEntity{ - @Id @GeneratedValue + @Id Long id; @ManyToOne - @JoinColumn(name = "id") Pet pet; @ManyToOne - @JoinColumn(name = "id") User user; } From 293eea91ee17a16df534fe417d82f841dc91f639 Mon Sep 17 00:00:00 2001 From: Antt02 Date: Tue, 2 Apr 2024 18:42:43 +0200 Subject: [PATCH 7/9] implementing favourite pets as one to many --- EntitiesModel.puml | 6 ++++++ .../demo/domain/{Favourite.java => FavouritedPets.java} | 8 +++----- src/main/java/cat/udl/eps/softarch/demo/domain/User.java | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) rename src/main/java/cat/udl/eps/softarch/demo/domain/{Favourite.java => FavouritedPets.java} (72%) diff --git a/EntitiesModel.puml b/EntitiesModel.puml index 08d033d7..876180c4 100644 --- a/EntitiesModel.puml +++ b/EntitiesModel.puml @@ -90,6 +90,11 @@ class MedicalRecord { date : Date } +class FavouritedPets { + id : Long + petId : Long +} + Pet "1" -- "*" MedicalRecord : has > @@ -104,4 +109,5 @@ Client "*" -> "*" Shelter : donate > Adoption "*" -> "1" Pet :adopted > Adoption "*" -> "1" User :adopt < ShelterVolunteer "1.*" -> "*" Shelter : works > +User "1" -> "*" FavouritedPets : hasFavourited > @enduml \ No newline at end of file diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java b/src/main/java/cat/udl/eps/softarch/demo/domain/FavouritedPets.java similarity index 72% rename from src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java rename to src/main/java/cat/udl/eps/softarch/demo/domain/FavouritedPets.java index 6364e8b0..63b5e5fc 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/FavouritedPets.java @@ -1,8 +1,8 @@ package cat.udl.eps.softarch.demo.domain; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; import jakarta.persistence.ManyToOne; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.EqualsAndHashCode; import org.springframework.data.annotation.Id; @@ -10,13 +10,11 @@ @EqualsAndHashCode(callSuper = true) @Entity @Data -public class Favourite extends UriEntity { +public class FavouritedPets extends UriEntity { @Id - @GeneratedValue + @NotNull Long id; - String test; - @ManyToOne Pet pet; diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/User.java b/src/main/java/cat/udl/eps/softarch/demo/domain/User.java index a7e9fa07..a4f686fb 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/User.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/User.java @@ -77,7 +77,7 @@ public boolean isEnabled() { return true; } - @ManyToMany - public List favouritedPets; + @OneToMany + public List favouritedPets; } From 32eac35bd497eb68bf3f5cf0ca57287e47540467 Mon Sep 17 00:00:00 2001 From: Antt02 Date: Tue, 2 Apr 2024 18:42:43 +0200 Subject: [PATCH 8/9] implementing favourite pets as one to many --- EntitiesModel.puml | 6 ++++++ .../domain/{Favourite.java => FavouritedPets.java} | 10 ++++------ .../java/cat/udl/eps/softarch/demo/domain/User.java | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) rename src/main/java/cat/udl/eps/softarch/demo/domain/{Favourite.java => FavouritedPets.java} (63%) diff --git a/EntitiesModel.puml b/EntitiesModel.puml index 08d033d7..876180c4 100644 --- a/EntitiesModel.puml +++ b/EntitiesModel.puml @@ -90,6 +90,11 @@ class MedicalRecord { date : Date } +class FavouritedPets { + id : Long + petId : Long +} + Pet "1" -- "*" MedicalRecord : has > @@ -104,4 +109,5 @@ Client "*" -> "*" Shelter : donate > Adoption "*" -> "1" Pet :adopted > Adoption "*" -> "1" User :adopt < ShelterVolunteer "1.*" -> "*" Shelter : works > +User "1" -> "*" FavouritedPets : hasFavourited > @enduml \ No newline at end of file diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java b/src/main/java/cat/udl/eps/softarch/demo/domain/FavouritedPets.java similarity index 63% rename from src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java rename to src/main/java/cat/udl/eps/softarch/demo/domain/FavouritedPets.java index 6364e8b0..b50bd463 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Favourite.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/FavouritedPets.java @@ -1,22 +1,20 @@ package cat.udl.eps.softarch.demo.domain; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; import jakarta.persistence.ManyToOne; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.EqualsAndHashCode; -import org.springframework.data.annotation.Id; +import jakarta.persistence.Id; @EqualsAndHashCode(callSuper = true) @Entity @Data -public class Favourite extends UriEntity { +public class FavouritedPets extends UriEntity { @Id - @GeneratedValue + @NotNull Long id; - String test; - @ManyToOne Pet pet; diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/User.java b/src/main/java/cat/udl/eps/softarch/demo/domain/User.java index a7e9fa07..a4f686fb 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/User.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/User.java @@ -77,7 +77,7 @@ public boolean isEnabled() { return true; } - @ManyToMany - public List favouritedPets; + @OneToMany + public List favouritedPets; } From 5b795901a2542278af3c7be6862a0eafbbbb214c Mon Sep 17 00:00:00 2001 From: Antt02 Date: Tue, 2 Apr 2024 18:55:46 +0200 Subject: [PATCH 9/9] local tests working now --- .../cat/udl/eps/softarch/demo/domain/FavouritedPets.java | 9 ++------- src/main/java/cat/udl/eps/softarch/demo/domain/User.java | 6 ++---- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/FavouritedPets.java b/src/main/java/cat/udl/eps/softarch/demo/domain/FavouritedPets.java index b50bd463..7fa9eb4f 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/FavouritedPets.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/FavouritedPets.java @@ -1,11 +1,10 @@ package cat.udl.eps.softarch.demo.domain; import jakarta.persistence.Entity; -import jakarta.persistence.ManyToOne; +import jakarta.persistence.Id; import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.EqualsAndHashCode; -import jakarta.persistence.Id; @EqualsAndHashCode(callSuper = true) @Entity @@ -15,9 +14,5 @@ public class FavouritedPets extends UriEntity { @NotNull Long id; - @ManyToOne - Pet pet; - - @ManyToOne - User user; + Long petId; } diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/User.java b/src/main/java/cat/udl/eps/softarch/demo/domain/User.java index a4f686fb..43a9b200 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/User.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/User.java @@ -1,12 +1,10 @@ package cat.udl.eps.softarch.demo.domain; import com.fasterxml.jackson.annotation.JsonProperty; - +import com.fasterxml.jackson.annotation.JsonValue; import jakarta.persistence.*; import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; - -import com.fasterxml.jackson.annotation.JsonValue; import lombok.Data; import lombok.EqualsAndHashCode; import org.hibernate.validator.constraints.Length; @@ -77,7 +75,7 @@ public boolean isEnabled() { return true; } - @OneToMany + @OneToMany(fetch = FetchType.EAGER) public List favouritedPets; }