Ignore:
Timestamp:
02/14/23 20:45:37 (17 months ago)
Author:
SazdovaEkaterina <sazdovaekaterina@…>
Branches:
main
Children:
59a8941
Parents:
3f5e485
Message:

adoption posts list + pet details page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PostController.java

    r3f5e485 ra762b3a  
    11package finki.paw5.web.controllers;
    22
     3import finki.paw5.model.entities.PersonalProfile;
    34import finki.paw5.model.entities.Pet;
    45import finki.paw5.model.entities.Post;
     6import finki.paw5.model.entities.Shelter;
    57import finki.paw5.model.enumerations.AgeGroup;
    68import finki.paw5.model.enumerations.Gender;
    79import finki.paw5.model.enumerations.Size;
    810import finki.paw5.model.enumerations.Species;
     11import finki.paw5.service.PersonalProfileService;
    912import finki.paw5.service.PetService;
    1013import finki.paw5.service.PostService;
     14import finki.paw5.service.ShelterService;
     15import jakarta.servlet.http.HttpServletRequest;
    1116import org.springframework.stereotype.Controller;
    1217import org.springframework.ui.Model;
    1318import org.springframework.web.bind.annotation.GetMapping;
     19import org.springframework.web.bind.annotation.PathVariable;
    1420import org.springframework.web.bind.annotation.PostMapping;
    1521import org.springframework.web.bind.annotation.RequestParam;
    1622
    1723import java.time.LocalDate;
     24import java.util.List;
    1825
    1926@Controller
     
    2229    private final PostService postService;
    2330    private final PetService petService;
     31    private final PersonalProfileService personalProfileService;
    2432
    25     public PostController(PostService postService, PetService petService) {
     33    public PostController(PostService postService, PetService petService, PersonalProfileService personalProfileService, ShelterService shelterService) {
    2634        this.postService = postService;
    2735        this.petService = petService;
     36        this.personalProfileService = personalProfileService;
    2837    }
    2938
     
    5463        return "redirect:/home";
    5564    }
     65
     66    @GetMapping("/adoption-posts")
     67    public String getAdoptionPosts(Model model, HttpServletRequest request){
     68
     69        List<Post> posts = this.postService.findAll();
     70        List<Pet> pets = this.petService.findAll();
     71        //model.addAttribute("posts", posts);
     72        //model.addAttribute("pets",pets);
     73        request.getSession().setAttribute("posts",posts);//temp
     74        request.getSession().setAttribute("pets",pets);//temp
     75
     76        return "list-posts-adoption";
     77    }
     78
     79    @GetMapping("/pet-details-{id}")
     80    public String getPostDetails(@PathVariable Integer id, Model model, HttpServletRequest request){
     81
     82        Post post = this.postService.findById(id).get();
     83        Pet pet = this.petService.findById(post.getPetId()).get();
     84
     85        //model.addAttribute("pet", pet);
     86        //model.addAttribute("post", post);
     87        request.getSession().setAttribute("post", post);//temp
     88        request.getSession().setAttribute("pet", pet);//temp
     89
     90        return "pet-details";
     91    }
    5692}
Note: See TracChangeset for help on using the changeset viewer.