Skip to content

Commit

Permalink
resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
pautorne committed Apr 3, 2024
2 parents 9d87549 + 54fba72 commit 922c9c3
Show file tree
Hide file tree
Showing 24 changed files with 481 additions and 33 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@
<artifactId>jackson-annotations</artifactId>
<version>2.15.3</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>3.2.2</version>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Adoptions.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,7 +19,7 @@
public class Adoptions {

@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@OneToOne
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +15,7 @@
public class Permission {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@NotNull
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Pet.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,6 +19,7 @@
public abstract class Pet extends UriEntity<Long> {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@NotBlank
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Role.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.Id;
import jakarta.persistence.Table;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand All @@ -11,10 +9,11 @@
@Table(name = "Role") // Nombre de la tabla en la base de datos
@Data
@EqualsAndHashCode(callSuper = true)
public class Role extends UriEntity<String> {
public class Role extends UriEntity<Long> {

@Id
private String id;
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@NotBlank
private String name;
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Shelter.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -19,7 +17,20 @@
@EqualsAndHashCode(callSuper = false)
public class Shelter extends UriEntity<Long> {

@ManyToOne
@JsonIdentityReference(alwaysAsId = true)
private User user;

@ManyToOne
@JsonIdentityReference(alwaysAsId = true)
private Pet pet;

@OneToOne
@JsonIdentityReference(alwaysAsId = true)
private ShelterCertificate shelterCertificate;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@NotBlank
Expand All @@ -31,7 +42,7 @@ public class Shelter extends UriEntity<Long> {
private String email;

@NotBlank
@Pattern(regexp="(^$|[0-9]{11})")
@Pattern(regexp="(^[+]*[(]?[0-9]{1,4}[)]?[-\\s./0-9]*$)")
private String mobile;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,6 +18,7 @@ public class ShelterCertificate {
private Shelter shelter;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Adoptions, String>, PagingAndSortingRepository<Adoptions, String> {
@RepositoryRestResource
public interface AdoptionsRepository extends CrudRepository<Adoptions, Long>, PagingAndSortingRepository<Adoptions, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cat, String>, PagingAndSortingRepository<Cat, String> {
@RepositoryRestResource
public interface CatRepository extends CrudRepository<Cat, Long>, PagingAndSortingRepository<Cat, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Dog, String>, PagingAndSortingRepository<Dog, String> {
@RepositoryRestResource
public interface DogRepository extends CrudRepository<Dog, Long>, PagingAndSortingRepository<Dog, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Location, String>, PagingAndSortingRepository<Location, String> {
@RepositoryRestResource
public interface LocationRepository extends CrudRepository<Location, Long>, PagingAndSortingRepository<Location, Long> {


}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pet, String>, PagingAndSortingRepository<Pet, String> {
@RepositoryRestResource
public interface PetRepository extends CrudRepository<Pet, Long>, PagingAndSortingRepository<Pet, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cat.udl.eps.softarch.demo.repository;

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

@RepositoryRestResource
public interface RoleRepository extends CrudRepository<Role, Long>, PagingAndSortingRepository<Role, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Schedule, String>, PagingAndSortingRepository<Schedule, String> {
@RepositoryRestResource
public interface ScheduleRepository extends CrudRepository<Schedule, Long>, PagingAndSortingRepository<Schedule, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShelterCertificate, String>, PagingAndSortingRepository<ShelterCertificate, String> {
@RepositoryRestResource
public interface ShelterCertificateRepository extends CrudRepository<ShelterCertificate, Long>, PagingAndSortingRepository<ShelterCertificate, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

@RepositoryRestResource
public interface ShelterRepository extends CrudRepository<Shelter, Long>, PagingAndSortingRepository<Shelter, Long> {
Shelter findByName(@Param("name") String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cat.udl.eps.softarch.demo.steps;

import cat.udl.eps.softarch.demo.domain.Shelter;
import cat.udl.eps.softarch.demo.repository.ShelterRepository;
import io.cucumber.java.en.And;
import io.cucumber.java.en.When;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;

import java.nio.charset.StandardCharsets;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.assertj.core.api.Assertions.assertThat;


public class DeleteShelterStepDefs {
@Autowired
private StepDefs stepDefs;

@Autowired
private ShelterRepository shelterRepository;

@When("^I delete the shelter with name \"([^\"]*)\"$")
public void iDeleteAShelterWithName(String name) throws Exception {
Shelter shelter = shelterRepository.findByName(name);

stepDefs.result = stepDefs.mockMvc.perform(
delete("/shelters/{id}", (shelter != null) ? shelter.getId() : "999")
.contentType(MediaType.APPLICATION_JSON)
.content(stepDefs.mapper.writeValueAsString(shelter))
.characterEncoding(StandardCharsets.UTF_8)
.accept(MediaType.APPLICATION_JSON)
.with(AuthenticationStepDefs.authenticate()))
.andDo(print());
}

@And("^The shelter with name \"([^\"]*)\" has been deleted$")
public void theShelterWithNameHasBeenDeleted(String name) {
Shelter shelter = shelterRepository.findByName(name);
assertThat(shelter).isNull();
}

@And("^The shelter with name \"([^\"]*)\" has not been deleted$")
public void theShelterWithNameHasNotBeenDeleted(String name) {
Shelter shelter = shelterRepository.findByName(name);
assertThat(shelter).isNotNull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cat.udl.eps.softarch.demo.steps;

import cat.udl.eps.softarch.demo.domain.Shelter;
import cat.udl.eps.softarch.demo.repository.ShelterRepository;
import io.cucumber.java.en.When;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;

import java.nio.charset.StandardCharsets;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;

public class GetShelterStepDefs {
@Autowired
private StepDefs stepDefs;

@Autowired
private ShelterRepository shelterRepository;

@When("^I retrieve the shelter with name \"([^\"]*)\"$")
public void iRetrieveShelterWithName(String name) throws Exception {
Shelter shelter = shelterRepository.findByName(name);

stepDefs.result = stepDefs.mockMvc.perform(
get("/shelters/{id}", (shelter != null) ? shelter.getId() : "999")
.contentType(MediaType.APPLICATION_JSON)
.content(stepDefs.mapper.writeValueAsString(shelter))
.characterEncoding(StandardCharsets.UTF_8)
.accept(MediaType.APPLICATION_JSON)
.with(AuthenticationStepDefs.authenticate()))
.andDo(print());
}
}
Loading

0 comments on commit 922c9c3

Please sign in to comment.