Skip to content

Commit

Permalink
Merge branch 'main' into crud-Shelter
Browse files Browse the repository at this point in the history
  • Loading branch information
vGerJ02 committed Feb 29, 2024
2 parents 5a9b92b + 99a1cd2 commit a6c489f
Show file tree
Hide file tree
Showing 17 changed files with 207 additions and 33 deletions.
5 changes: 3 additions & 2 deletions EntitiesModel.puml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ class ShelterCertificate {

class SocialNetworks {
id: Integer
instagram: String
twitter: String
username: String
typeOfSocialNetwork: String
url: String
}

class Schedule {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cat.udl.eps.softarch.demo.domain;

import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;

import java.util.Collection;

@EqualsAndHashCode(callSuper = true)
@Entity
@Data
public class Client extends User {
@Override
@ElementCollection
public Collection<GrantedAuthority> getAuthorities(){
return AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_CLIENT");
}
}
14 changes: 8 additions & 6 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Location.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
package cat.udl.eps.softarch.demo.domain;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Entity
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor

public class Location extends UriEntity<Long>{
public class Location extends UriEntity<Long> {
@Id
private Long id;

private String address;

private float latitude;

private float longitude;

private String province;
private float latitude;

private String municipality;

private String postalCode;

@OneToOne
@JoinColumn(name = "shelter_id")
private Shelter shelter;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
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.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
Expand All @@ -28,4 +25,7 @@ public class MedicalRecord extends UriEntity<Long> {

@NotNull
private ZonedDateTime date;

@ManyToOne
private Pet pet;
}
10 changes: 7 additions & 3 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Pet.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cat.udl.eps.softarch.demo.domain;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

Expand All @@ -22,4 +20,10 @@ public class Pet extends UriEntity<Long> {
String age;
String description;
String breed;


@ManyToOne
public Shelter isIn;
@ManyToMany
public User[] favouritedBy;
}
9 changes: 7 additions & 2 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.Date;

@Entity
Expand All @@ -17,8 +19,11 @@ public class Schedule extends UriEntity<Long> {
private Long id;

@NotNull
private Date start;
private LocalDateTime start;

@NotNull
private Date finish;
private LocalDateTime finish;

@ManyToOne
public Shelter available;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
package cat.udl.eps.softarch.demo.domain;

import java.util.Date;
import java.time.ZonedDateTime;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
@Entity
public class ShelterCertificate extends UriEntity<Long> {


@Id
@GeneratedValue()
private Long id;
private Date expirationDate;

@Override
public Long getId() {
return id;
}
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@NotNull
private ZonedDateTime expirationDate;

@JsonIdentityReference(alwaysAsId = true)
@ManyToOne
private Shelter shelterServed;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package cat.udl.eps.softarch.demo.domain;

public class ShelterVolunteer extends User {
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
@Entity
public class ShelterVolunteer extends User {
@JsonIdentityReference(alwaysAsId = true)
@ManyToOne
private Shelter userShelter;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
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.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

Expand All @@ -13,7 +9,11 @@
public class SocialNetworks extends UriEntity<Long> {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
String instagram;
String twitter;
private Long id;
private String instagram;
private String twitter;

@ManyToOne
public Shelter belongsTo;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cat.udl.eps.softarch.demo.repository;

import cat.udl.eps.softarch.demo.domain.Admin;
import cat.udl.eps.softarch.demo.domain.User;

import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface AdminRepository extends CrudRepository<Admin, String>, PagingAndSortingRepository<Admin, String> {
List<User> findByIdContaining(@Param("text") String text);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cat.udl.eps.softarch.demo.repository;

import cat.udl.eps.softarch.demo.domain.Client;
import cat.udl.eps.softarch.demo.domain.User;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.List;

@RepositoryRestResource
public interface ClientRepository extends CrudRepository<Client, String>, PagingAndSortingRepository<Client, String> {

/* Interface provides automatically, as defined in
* https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/CrudRepository.html
* and
* https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/PagingAndSortingRepository.html
* the methods: count, delete, deleteAll, deleteById, existsById, findAll, findAllById, findById, save, saveAll,...
*
* Additional methods like findByUsernameContaining can be defined following:
* https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation
*/

List<User> findByIdContaining(@Param("text") String text);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cat.udl.eps.softarch.demo.repository;

import cat.udl.eps.softarch.demo.domain.Location;
import cat.udl.eps.softarch.demo.domain.Shelter;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

@RepositoryRestResource
public interface LocationRepository extends CrudRepository<Location, Long>, PagingAndSortingRepository<Location, Long> {

Location findByShelterId(@Param("shelter_id") Long shelterId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cat.udl.eps.softarch.demo.repository;

import cat.udl.eps.softarch.demo.domain.Pet;
import cat.udl.eps.softarch.demo.domain.User;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface PetRepository extends CrudRepository<Pet, Long>, PagingAndSortingRepository<Pet, Long> {
List<User> findBySize(@Param("size") String size);
//List<Shelter> findByShelter(@Param("Shelter") Shelter shelter);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cat.udl.eps.softarch.demo.repository;

import cat.udl.eps.softarch.demo.domain.Schedule;
import cat.udl.eps.softarch.demo.domain.Shelter;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.repository.PagingAndSortingRepository;


import java.util.List;

public interface ScheduleRepository extends CrudRepository<Schedule, Long>, PagingAndSortingRepository<Schedule, Long>{

//Get list of scheduled of a specific shelter
List<Schedule> findByAvailable(@Param("shelter") Shelter shelter);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cat.udl.eps.softarch.demo.repository;

import cat.udl.eps.softarch.demo.domain.ShelterCertificate;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;

public interface ShelterCertificateRepository extends CrudRepository<ShelterCertificate, Long>, PagingAndSortingRepository<ShelterCertificate, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cat.udl.eps.softarch.demo.repository;

import cat.udl.eps.softarch.demo.domain.ShelterVolunteer;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;

public interface ShelterVolunteerRepository extends CrudRepository<ShelterVolunteer, String>, PagingAndSortingRepository<ShelterVolunteer, String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cat.udl.eps.softarch.demo.repository;

import cat.udl.eps.softarch.demo.domain.SocialNetworks;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

@RepositoryRestResource
public interface SocialNetworksRepository extends CrudRepository<SocialNetworks,Long> {

}

0 comments on commit a6c489f

Please sign in to comment.