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

adoption posts list + pet details page

Location:
Prototype Application/Paw5/src/main
Files:
6 added
3 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/PersonalProfile.java

    r3f5e485 ra762b3a  
    3232    private GroomingNeed groomingNeed;
    3333
    34     public PersonalProfile(int id, 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) {
    3535        this.id = id;
    3636        this.friendlyToKids = friendlyToKids;
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/PetService.java

    r3f5e485 ra762b3a  
    22
    33import finki.paw5.model.entities.Pet;
     4import finki.paw5.web.controllers.PostController;
     5
     6import java.util.List;
     7import java.util.Optional;
    48
    59public interface PetService {
    610
    711    void save (Pet pet);
     12
     13    List<Pet> findAll();
     14
     15    Optional<Pet> findById(Integer petId);
    816}
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/PostService.java

    r3f5e485 ra762b3a  
    22
    33import finki.paw5.model.entities.Post;
    4 import finki.paw5.model.enumerations.AgeGroup;
    5 import finki.paw5.model.enumerations.Gender;
    6 import finki.paw5.model.enumerations.Size;
    7 import finki.paw5.model.enumerations.Species;
     4
     5import java.util.List;
     6import java.util.Optional;
    87
    98public interface PostService {
     
    1110    void save (Post post);
    1211
     12    List<Post> findAll();
     13
     14    Optional<Post> findById(Integer id);
    1315}
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/PetServiceImplementation.java

    r3f5e485 ra762b3a  
    55import finki.paw5.service.PetService;
    66import org.springframework.stereotype.Service;
     7
     8import java.util.List;
     9import java.util.Optional;
    710
    811@Service
     
    1922        this.petRepository.save(pet);
    2023    }
     24
     25    @Override
     26    public List<Pet> findAll() {
     27        return this.petRepository.findAll();
     28    }
     29
     30    @Override
     31    public Optional<Pet> findById(Integer petId) {
     32        return this.petRepository.findById(petId);
     33    }
    2134}
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/PostServiceImplementation.java

    r3f5e485 ra762b3a  
    55import finki.paw5.service.PostService;
    66import org.springframework.stereotype.Service;
     7
     8import java.util.List;
     9import java.util.Optional;
    710
    811@Service
     
    2023    }
    2124
     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    }
    2234}
  • 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.