From 71f784125b5210f82e1022f29f35a5cf6db11d95 Mon Sep 17 00:00:00 2001 From: LordDangerous Date: Thu, 7 Mar 2024 15:50:37 +0100 Subject: [PATCH 1/3] Implemented shelter relations and repository --- .../udl/eps/softarch/demo/domain/Shelter.java | 27 ++++++++++++++----- .../demo/repository/ShelterRepository.java | 9 +++++++ 2 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/main/java/cat/udl/eps/softarch/demo/repository/ShelterRepository.java 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 2c8eb0d..6befbf9 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 @@ -1,16 +1,14 @@ package cat.udl.eps.softarch.demo.domain; -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 com.fasterxml.jackson.annotation.JsonIdentityReference; +import jakarta.persistence.*; import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; import jdk.jfr.BooleanFlag; +import lombok.Data; import lombok.EqualsAndHashCode; -import org.hibernate.validator.constraints.Length; import java.time.LocalDateTime; @@ -19,6 +17,21 @@ @EqualsAndHashCode(callSuper = false) public class Shelter extends UriEntity { + @ManyToOne + @NotNull + @JsonIdentityReference(alwaysAsId = true) + private User user; + + @ManyToOne + @NotNull + @JsonIdentityReference(alwaysAsId = true) + private Pet pet; + + @OneToOne + @NotNull + @JsonIdentityReference(alwaysAsId = true) + private ShelterCertificate shelterCertificate; + @Id private Long id; 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 new file mode 100644 index 0000000..faa685d --- /dev/null +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterRepository.java @@ -0,0 +1,9 @@ +package cat.udl.eps.softarch.demo.repository; + +import cat.udl.eps.softarch.demo.domain.Shelter; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.PagingAndSortingRepository; + +public interface ShelterRepository extends CrudRepository, PagingAndSortingRepository { + Shelter findName(String name); +} \ No newline at end of file From 302a739a41e555815fb0bb84673a661e68887113 Mon Sep 17 00:00:00 2001 From: LordDangerous Date: Thu, 7 Mar 2024 16:05:30 +0100 Subject: [PATCH 2/3] Multiple fixes --- .../java/cat/udl/eps/softarch/demo/domain/Adoptions.java | 7 ++----- .../java/cat/udl/eps/softarch/demo/domain/Permission.java | 3 +++ src/main/java/cat/udl/eps/softarch/demo/domain/Pet.java | 6 ++---- src/main/java/cat/udl/eps/softarch/demo/domain/Role.java | 7 +++---- .../java/cat/udl/eps/softarch/demo/domain/Schedule.java | 7 ++----- .../java/cat/udl/eps/softarch/demo/domain/Shelter.java | 1 + .../udl/eps/softarch/demo/domain/ShelterCertificate.java | 5 ++--- .../eps/softarch/demo/repository/AdoptionsRepository.java | 4 +++- .../udl/eps/softarch/demo/repository/CatRepository.java | 4 +++- .../udl/eps/softarch/demo/repository/DogRepository.java | 4 +++- .../eps/softarch/demo/repository/LocationRepository.java | 4 +++- .../udl/eps/softarch/demo/repository/PetRepository.java | 4 +++- .../eps/softarch/demo/repository/ScheduleRepository.java | 4 +++- .../demo/repository/ShelterCertificateRepository.java | 4 +++- .../eps/softarch/demo/repository/ShelterRepository.java | 6 ++++-- 15 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Adoptions.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Adoptions.java index 5f97e86..f397141 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Adoptions.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Adoptions.java @@ -1,8 +1,5 @@ package cat.udl.eps.softarch.demo.domain; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.OneToOne; +import jakarta.persistence.*; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.Data; @@ -22,7 +19,7 @@ public class Adoptions { @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @OneToOne diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Permission.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Permission.java index 53e4c36..b1fc8ff 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Permission.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Permission.java @@ -1,6 +1,8 @@ package cat.udl.eps.softarch.demo.domain; import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; @@ -13,6 +15,7 @@ public class Permission { @Id + @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @NotNull diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Pet.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Pet.java index cafe8ed..97e5bea 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Pet.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Pet.java @@ -1,10 +1,7 @@ package cat.udl.eps.softarch.demo.domain; import com.fasterxml.jackson.annotation.JsonIdentityReference; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToOne; +import jakarta.persistence.*; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; @@ -22,6 +19,7 @@ public abstract class Pet extends UriEntity { @Id + @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @NotBlank diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Role.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Role.java index ed51a2f..300949e 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Role.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Role.java @@ -1,8 +1,6 @@ package cat.udl.eps.softarch.demo.domain; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import jakarta.persistence.*; import jakarta.validation.constraints.NotBlank; import lombok.Data; import lombok.EqualsAndHashCode; @@ -14,7 +12,8 @@ public class Role extends UriEntity { @Id - private String id; + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; @NotBlank private String name; diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Schedule.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Schedule.java index 34a5fb6..19b34fa 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Schedule.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Schedule.java @@ -2,10 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIdentityReference; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.ManyToOne; +import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.EqualsAndHashCode; @@ -18,7 +15,7 @@ public class Schedule { @Id - @GeneratedValue + @GeneratedValue(strategy = GenerationType.AUTO) private int Id; @NotNull 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 6befbf9..725876e 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 @@ -33,6 +33,7 @@ public class Shelter extends UriEntity { private ShelterCertificate shelterCertificate; @Id + @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @NotBlank diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/ShelterCertificate.java b/src/main/java/cat/udl/eps/softarch/demo/domain/ShelterCertificate.java index 730f2d4..9d50754 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/ShelterCertificate.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/ShelterCertificate.java @@ -1,9 +1,7 @@ package cat.udl.eps.softarch.demo.domain; import com.fasterxml.jackson.annotation.JsonIdentityReference; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.OneToOne; +import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.EqualsAndHashCode; @@ -20,6 +18,7 @@ public class ShelterCertificate { private Shelter shelter; @Id + @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @NotNull diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/AdoptionsRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/AdoptionsRepository.java index 5101d0b..cdc69fb 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/repository/AdoptionsRepository.java +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/AdoptionsRepository.java @@ -3,6 +3,8 @@ import cat.udl.eps.softarch.demo.domain.Adoptions; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; -public interface AdoptionsRepository extends CrudRepository, PagingAndSortingRepository { +@RepositoryRestResource +public interface AdoptionsRepository extends CrudRepository, PagingAndSortingRepository { } diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/CatRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/CatRepository.java index 48c8445..e92592a 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/repository/CatRepository.java +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/CatRepository.java @@ -3,6 +3,8 @@ import cat.udl.eps.softarch.demo.domain.Cat; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; -public interface CatRepository extends CrudRepository, PagingAndSortingRepository { +@RepositoryRestResource +public interface CatRepository extends CrudRepository, PagingAndSortingRepository { } diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/DogRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/DogRepository.java index 5e83b4c..e068275 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/repository/DogRepository.java +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/DogRepository.java @@ -3,6 +3,8 @@ import cat.udl.eps.softarch.demo.domain.Dog; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; -public interface DogRepository extends CrudRepository, PagingAndSortingRepository { +@RepositoryRestResource +public interface DogRepository extends CrudRepository, PagingAndSortingRepository { } diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/LocationRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/LocationRepository.java index ea42215..e705bd3 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/repository/LocationRepository.java +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/LocationRepository.java @@ -4,8 +4,10 @@ import cat.udl.eps.softarch.demo.domain.User; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; -public interface LocationRepository extends CrudRepository, PagingAndSortingRepository { +@RepositoryRestResource +public interface LocationRepository extends CrudRepository, PagingAndSortingRepository { } diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/PetRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/PetRepository.java index d7edc69..0e4cbc5 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/repository/PetRepository.java +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/PetRepository.java @@ -3,6 +3,8 @@ import cat.udl.eps.softarch.demo.domain.Pet; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; -public interface PetRepository extends CrudRepository, PagingAndSortingRepository { +@RepositoryRestResource +public interface PetRepository extends CrudRepository, PagingAndSortingRepository { } diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/ScheduleRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/ScheduleRepository.java index 9f7555f..aa60082 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/repository/ScheduleRepository.java +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/ScheduleRepository.java @@ -3,7 +3,9 @@ import cat.udl.eps.softarch.demo.domain.Schedule; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; -public interface ScheduleRepository extends CrudRepository, PagingAndSortingRepository { +@RepositoryRestResource +public interface ScheduleRepository extends CrudRepository, PagingAndSortingRepository { } diff --git a/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterCertificateRepository.java b/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterCertificateRepository.java index 37f578f..a56fbc5 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterCertificateRepository.java +++ b/src/main/java/cat/udl/eps/softarch/demo/repository/ShelterCertificateRepository.java @@ -3,7 +3,9 @@ import cat.udl.eps.softarch.demo.domain.ShelterCertificate; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; -public interface ShelterCertificateRepository extends CrudRepository, PagingAndSortingRepository { +@RepositoryRestResource +public interface ShelterCertificateRepository extends CrudRepository, PagingAndSortingRepository { } \ 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 faa685d..78b6dc1 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 @@ -3,7 +3,9 @@ import cat.udl.eps.softarch.demo.domain.Shelter; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource +public interface ShelterRepository extends CrudRepository, PagingAndSortingRepository { -public interface ShelterRepository extends CrudRepository, PagingAndSortingRepository { - Shelter findName(String name); } \ No newline at end of file From 070613bb623438461d71021fefc4e02f7cd64470 Mon Sep 17 00:00:00 2001 From: LordDangerous Date: Thu, 7 Mar 2024 16:08:59 +0100 Subject: [PATCH 3/3] Multiple fixes --- src/main/java/cat/udl/eps/softarch/demo/domain/Role.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/cat/udl/eps/softarch/demo/domain/Role.java b/src/main/java/cat/udl/eps/softarch/demo/domain/Role.java index 300949e..f0d6346 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/domain/Role.java +++ b/src/main/java/cat/udl/eps/softarch/demo/domain/Role.java @@ -9,7 +9,7 @@ @Table(name = "Role") // Nombre de la tabla en la base de datos @Data @EqualsAndHashCode(callSuper = true) -public class Role extends UriEntity { +public class Role extends UriEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO)