Changeset e76c5a6 for Prototype Application/Paw5/src
- Timestamp:
- 03/08/23 17:43:21 (20 months ago)
- Branches:
- main
- Children:
- 5dea0b7
- Parents:
- c03e53b
- Location:
- Prototype Application/Paw5/src/main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/AuthServiceImplementation.java
rc03e53b re76c5a6 3 3 import finki.paw5.model.entities.Adopter; 4 4 import finki.paw5.model.entities.Employee; 5 import finki.paw5.model.entities.Shelter; 5 6 import finki.paw5.model.entities.User; 6 7 import finki.paw5.model.enumerations.FreeTime; … … 10 11 import finki.paw5.repository.AdopterRepository; 11 12 import finki.paw5.repository.EmployeeRepository; 13 import finki.paw5.repository.ShelterRepository; 12 14 import finki.paw5.repository.UserRepository; 13 15 import finki.paw5.service.AuthService; … … 22 24 private final AdopterRepository adopterRepository; 23 25 private final EmployeeRepository employeeRepository; 26 private final ShelterRepository shelterRepository; 24 27 25 public AuthServiceImplementation(UserRepository userRepository, AdopterRepository adopterRepository, EmployeeRepository employeeRepository ) {28 public AuthServiceImplementation(UserRepository userRepository, AdopterRepository adopterRepository, EmployeeRepository employeeRepository, ShelterRepository shelterRepository) { 26 29 this.userRepository = userRepository; 27 30 this.adopterRepository = adopterRepository; 28 31 this.employeeRepository = employeeRepository; 32 this.shelterRepository = shelterRepository; 29 33 } 30 34 … … 47 51 @Override 48 52 public Employee registerEmployee(String name, String email, String password, String telephone, String position, Integer shelterId) { 49 Employee employee = new Employee(LocalDate.now(),name, email,password,telephone,position,shelterId,false); 53 Shelter shelter = this.shelterRepository.findById(shelterId).get(); 54 Employee employee = new Employee(LocalDate.now(),name, email,password,telephone,position,shelter,false); 50 55 return employeeRepository.save(employee); 51 56 } -
Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PetController.java
rc03e53b re76c5a6 1 1 package finki.paw5.web.controllers; 2 2 3 import finki.paw5.model.entities.Adopter; 3 4 import finki.paw5.model.entities.Adoption; 4 5 import finki.paw5.model.entities.Pet; 5 import finki.paw5.model.entities.User;6 import finki.paw5.model.exceptions.InvalidPetIdException;7 6 import finki.paw5.service.AdoptionService; 8 7 import finki.paw5.service.PetService; … … 25 24 } 26 25 27 @PostMapping("/submit-adopt on-{id}")26 @PostMapping("/submit-adoption-{id}") 28 27 public String saveAdoption(@PathVariable Integer id, HttpServletRequest request) { 29 28 30 29 Pet pet = this.petService.findById(id); 31 30 32 User user = (User) request.getSession().getAttribute("user");31 Adopter adopter = (Adopter) request.getSession().getAttribute("user"); 33 32 34 Adoption adoption = new Adoption(LocalDate.now(), null, false, user.getId());33 Adoption adoption = new Adoption(LocalDate.now(), null, false, adopter); 35 34 this.adoptionService.save(adoption); 36 35 37 pet.setAdoption Id(adoption.getId());36 pet.setAdoption(adoption); 38 37 this.petService.save(pet); 39 38 -
Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PostController.java
rc03e53b re76c5a6 58 58 if(newPetCheckbox == true){ 59 59 60 Pet newPet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, employee.getShelter Id());60 Pet newPet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, employee.getShelter()); 61 61 this.petService.save(newPet); 62 62 63 Post post = new Post(LocalDate.now(), imageUrl, newPet .getId(), null, employee.getId());63 Post post = new Post(LocalDate.now(), imageUrl, newPet, null, employee); 64 64 this.postService.save(post); 65 65 … … 68 68 Pet selectedPet = this.petService.findById(petId); 69 69 70 Post post = new Post(LocalDate.now(), imageUrl, selectedPet .getId(), null, employee.getId());70 Post post = new Post(LocalDate.now(), imageUrl, selectedPet, null, employee); 71 71 this.postService.save(post); 72 72 … … 92 92 93 93 Post post = this.postService.findById(id).get(); 94 Pet pet = this.petService.findById(post.getPetId());94 Pet pet = post.getPet(); 95 95 96 96 model.addAttribute("pet", pet); -
Prototype Application/Paw5/src/main/resources/templates/list-posts-adoption.html
rc03e53b re76c5a6 47 47 <tr th:each = "post : ${posts}"> 48 48 <td th:text = "${post.getId()}"></td> 49 <td th: each = "pet : ${pets}" th:if="${post.getPetId()==pet.getId()}" th:text = "${pet.getName()}"></td>50 <td th: each = "pet : ${pets}" th:if="${post.getPetId()==pet.getId()}" th:text = "${pet.getSpecies()}"></td>49 <td th:text = "${post.getPet().getName()}"></td> 50 <td th:text = "${post.getPet().getSpecies()}"></td> 51 51 <td> 52 52 <form th:action="@{'/pet-details-{id}' (id=${post.getId()})}" -
Prototype Application/Paw5/src/main/resources/templates/pet-details.html
rc03e53b re76c5a6 68 68 </table> 69 69 <form method="POST" 70 th:action="@{'/submit-adopt on-{id}' (id=${pet.getId()})}"71 th:if="${pet.getAdoption Id()==null}">70 th:action="@{'/submit-adoption-{id}' (id=${pet.getId()})}" 71 th:if="${pet.getAdoption==null}"> 72 72 <button id="submit" 73 73 type="submit"
Note:
See TracChangeset
for help on using the changeset viewer.