Changes in / [f194b4e:eac569a]
- 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 reac569a 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 reac569a 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 reac569a 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 reac569a 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 reac569a 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 reac569a 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 reac569a 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 reac569a 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 reac569a 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, HttpServletRequest request){ 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 request.getSession().setAttribute("posts",posts);//temp 86 request.getSession().setAttribute("pets",pets);//temp 87 88 return "list-posts-adoption"; 89 } 90 91 @GetMapping("/pet-details-{id}") 92 public String getPostDetails(@PathVariable Integer id, Model model, HttpServletRequest request){ 93 94 Post post = this.postService.findById(id).get(); 95 Pet pet = this.petService.findById(post.getPetId()); 96 97 //model.addAttribute("pet", pet); 98 //model.addAttribute("post", post); 99 request.getSession().setAttribute("post", post);//temp 100 request.getSession().setAttribute("pet", pet);//temp 101 102 if(pet.getAdoptionId() != null){ 103 request.getSession().setAttribute("disableAdoption", true); 104 } else{ 105 request.getSession().setAttribute("disableAdoption", false); 106 } 107 108 return "pet-details"; 109 } 73 110 } -
Prototype Application/Paw5/src/main/resources/templates/aboutUs.html
rf194b4e reac569a 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 reac569a 43 43 <h1>Welcome to Paw 5</h1> 44 44 <h3>Let's get started 45 <th:block th:text="${session.user .getName()}"></th:block>45 <th:block th:text="${session.user?.getName()}"></th:block> 46 46 </h3> 47 47 </div> 48 48 <div> 49 <form method="get" th:action="@{'/adoption-posts'}"> 50 <button id="submit" type="submit">View Adoption posts</button> 51 </form> 52 </div> 49 53 </body> 50 54 </html>
Note:
See TracChangeset
for help on using the changeset viewer.