Changeset 8b7dd7f for Prototype Application/Paw5
- Timestamp:
- 03/05/23 18:01:28 (20 months ago)
- Branches:
- main
- Children:
- c3278ac, fdd7961
- Parents:
- f194b4e (diff), 5f53114 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Filip Chorbeski <86695898+FilipChorbeski@…> (03/05/23 18:01:28)
- git-committer:
- GitHub <noreply@…> (03/05/23 18:01:28)
- Location:
- Prototype Application/Paw5/src/main
- Files:
-
- 7 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Adoption.java
rf194b4e r8b7dd7f 5 5 6 6 import java.time.LocalDate; 7 import java.util.Date;8 7 9 8 @Data … … 27 26 28 27 @Column(name = "id_adopter", nullable = false) 29 private intadopterId;28 private Integer adopterId; 30 29 31 public Adoption(LocalDate startDate, LocalDate endDateFoster, boolean approved, intadopterId) {30 public Adoption(LocalDate startDate, LocalDate endDateFoster, boolean approved, Integer adopterId) { 32 31 this.startDate = startDate; 33 32 this.endDateFoster = endDateFoster; -
Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/PersonalProfile.java
rf194b4e r8b7dd7f 32 32 private GroomingNeed groomingNeed; 33 33 34 public PersonalProfile( intid, FriendlyToKids friendlyToKids, FriendlyToPets friendlyToPets, AttentionNeed attentionNeed, PhysicalActivity physicalActivity, GroomingNeed groomingNeed) {34 public PersonalProfile(Integer id, FriendlyToKids friendlyToKids, FriendlyToPets friendlyToPets, AttentionNeed attentionNeed, PhysicalActivity physicalActivity, GroomingNeed groomingNeed) { 35 35 this.id = id; 36 36 this.friendlyToKids = friendlyToKids; -
Prototype Application/Paw5/src/main/java/finki/paw5/service/PostService.java
rf194b4e r8b7dd7f 2 2 3 3 import finki.paw5.model.entities.Post; 4 import java.util.List; 5 import java.util.Optional; 4 6 5 7 public interface PostService { … … 7 9 void save (Post post); 8 10 11 List<Post> findAll(); 12 13 Optional<Post> findById(Integer id); 9 14 } -
Prototype Application/Paw5/src/main/java/finki/paw5/service/ShelterService.java
rf194b4e r8b7dd7f 4 4 5 5 import java.util.List; 6 import java.util.Optional; 6 7 7 8 public interface ShelterService { 9 Optional<Shelter> findById(Integer id); 8 10 List<Shelter> listShelters(); 9 11 } -
Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/PetServiceImplementation.java
rf194b4e r8b7dd7f 22 22 } 23 23 24 @Override25 24 public List<Pet> listpets() {return this.petRepository.findAll();} 26 25 -
Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/PostServiceImplementation.java
rf194b4e r8b7dd7f 5 5 import finki.paw5.service.PostService; 6 6 import org.springframework.stereotype.Service; 7 8 import java.util.List; 9 import java.util.Optional; 7 10 8 11 @Service … … 20 23 } 21 24 25 @Override 26 public List<Post> findAll() { 27 return this.postRepository.findAll(); 28 } 29 30 @Override 31 public Optional<Post> findById(Integer id) { 32 return this.postRepository.findById(id); 33 } 22 34 } -
Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/ShelterServiceImplementation.java
rf194b4e r8b7dd7f 7 7 8 8 import java.util.List; 9 import java.util.Optional; 9 10 10 11 @Service 11 12 public class ShelterServiceImplementation implements ShelterService { 13 12 14 private final ShelterRepository shelterRepository; 13 15 … … 16 18 } 17 19 20 @Override 21 public Optional<Shelter> findById(Integer id) { 22 return this.shelterRepository.findById(id); 23 } 18 24 19 25 @Override … … 21 27 return shelterRepository.findAll(); 22 28 } 29 30 23 31 } -
Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PetController.java
rf194b4e r8b7dd7f 1 1 package finki.paw5.web.controllers; 2 2 3 import finki.paw5.model.entities.Adoption; 4 import finki.paw5.model.entities.Pet; 5 import finki.paw5.model.entities.User; 6 import finki.paw5.model.exceptions.InvalidPetIdException; 7 import finki.paw5.service.AdoptionService; 3 8 import finki.paw5.service.PetService; 9 import jakarta.servlet.http.HttpServletRequest; 4 10 import org.springframework.stereotype.Controller; 11 import org.springframework.web.bind.annotation.PathVariable; 12 import org.springframework.web.bind.annotation.PostMapping; 13 14 import java.time.LocalDate; 5 15 6 16 @Controller … … 8 18 9 19 private final PetService petService; 20 private final AdoptionService adoptionService; 10 21 11 public PetController(PetService petService ) {22 public PetController(PetService petService, AdoptionService adoptionService) { 12 23 this.petService = petService; 24 this.adoptionService = adoptionService; 13 25 } 14 26 27 @PostMapping("/submit-adopton-{id}") 28 public String saveAdoption(@PathVariable Integer id, HttpServletRequest request) { 29 30 Pet pet = this.petService.findById(id); 31 32 User user = (User) request.getSession().getAttribute("user"); 33 34 Adoption adoption = new Adoption(LocalDate.now(), null, false, user.getId()); 35 this.adoptionService.save(adoption); 36 37 pet.setAdoptionId(adoption.getId()); 38 this.petService.save(pet); 39 40 return "redirect:/home"; 41 } 15 42 } -
Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PostController.java
rf194b4e r8b7dd7f 1 1 package finki.paw5.web.controllers; 2 3 import finki.paw5.model.entities.Employee;4 2 import finki.paw5.model.entities.Pet; 5 3 import finki.paw5.model.entities.Post; 6 import finki.paw5.model.entities. User;4 import finki.paw5.model.entities.Employee; 7 5 import finki.paw5.model.enumerations.AgeGroup; 8 6 import finki.paw5.model.enumerations.Gender; 9 7 import finki.paw5.model.enumerations.Size; 10 8 import finki.paw5.model.enumerations.Species; 9 import finki.paw5.service.PersonalProfileService; 11 10 import finki.paw5.service.PetService; 12 11 import finki.paw5.service.PostService; 12 import finki.paw5.service.ShelterService; 13 13 import jakarta.servlet.http.HttpServletRequest; 14 14 import org.springframework.stereotype.Controller; 15 15 import org.springframework.ui.Model; 16 16 import org.springframework.web.bind.annotation.GetMapping; 17 import org.springframework.web.bind.annotation.PathVariable; 17 18 import org.springframework.web.bind.annotation.PostMapping; 18 19 import org.springframework.web.bind.annotation.RequestParam; 19 20 20 21 import java.time.LocalDate; 22 import java.util.List; 21 23 22 24 @Controller … … 25 27 private final PostService postService; 26 28 private final PetService petService; 29 private final PersonalProfileService personalProfileService; 27 30 28 public PostController(PostService postService, PetService petService ) {31 public PostController(PostService postService, PetService petService, PersonalProfileService personalProfileService, ShelterService shelterService) { 29 32 this.postService = postService; 30 33 this.petService = petService; 34 this.personalProfileService = personalProfileService; 31 35 } 32 36 … … 71 75 return "redirect:/home"; 72 76 } 77 78 @GetMapping("/adoption-posts") 79 public String getAdoptionPosts(Model model){ 80 81 List<Post> posts = this.postService.findAll(); 82 List<Pet> pets = this.petService.listpets(); 83 model.addAttribute("posts", posts); 84 model.addAttribute("pets",pets); 85 86 return "list-posts-adoption"; 87 } 88 89 @GetMapping("/pet-details-{id}") 90 public String getPostDetails(@PathVariable Integer id, 91 Model model){ 92 93 Post post = this.postService.findById(id).get(); 94 Pet pet = this.petService.findById(post.getPetId()); 95 96 model.addAttribute("pet", pet); 97 model.addAttribute("post", post); 98 99 return "pet-details"; 100 } 73 101 } -
Prototype Application/Paw5/src/main/resources/templates/aboutUs.html
rf194b4e r8b7dd7f 40 40 <h5 class="text-center text-danger"> 41 41 You successfully logged in 42 <th:block th:text="${session.user .getId()}"></th:block>42 <th:block th:text="${session.user?.getId()}"></th:block> 43 43 </h5> 44 44 </div> -
Prototype Application/Paw5/src/main/resources/templates/home.html
rf194b4e r8b7dd7f 36 36 </header> 37 37 <div> 38 <h1>Welcome to Paw 5</h1> 39 <h3>Let's get started 40 <th:block th:text="${session.user?.getName()}"></th:block> 41 </h3> 42 </div> 43 <div> 38 44 <form method="get" th:action="@{'/create-post'}"> 39 <button id="submit" type="submit">Create an Adoption Post</button> 45 <button id="createPost" 46 type="submit" 47 class="btn">Create an Adoption Post</button> 40 48 </form> 41 49 </div> 42 50 <div> 43 <h1>Welcome to Paw 5</h1> 44 <h3>Let's get started 45 <th:block th:text="${session.user.getName()}"></th:block> 46 </h3> 51 <form method="get" th:action="@{'/adoption-posts'}"> 52 <button id="submit" 53 type="submit" 54 class="btn">View Pet Posts</button> 55 </form> 47 56 </div> 48 49 57 </body> 50 58 </html>
Note:
See TracChangeset
for help on using the changeset viewer.