Ignore:
Timestamp:
03/05/23 18:01:28 (20 months ago)
Author:
GitHub <noreply@…>
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)
Message:

Merge pull request #8 from SazdovaEkaterina/adopting-a-pet

Adopting a Pet

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  
    55
    66import java.time.LocalDate;
    7 import java.util.Date;
    87
    98@Data
     
    2726
    2827    @Column(name = "id_adopter", nullable = false)
    29     private int adopterId;
     28    private Integer adopterId;
    3029
    31     public Adoption(LocalDate startDate, LocalDate endDateFoster, boolean approved, int adopterId) {
     30    public Adoption(LocalDate startDate, LocalDate endDateFoster, boolean approved, Integer adopterId) {
    3231        this.startDate = startDate;
    3332        this.endDateFoster = endDateFoster;
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/PersonalProfile.java

    rf194b4e r8b7dd7f  
    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/PostService.java

    rf194b4e r8b7dd7f  
    22
    33import finki.paw5.model.entities.Post;
     4import java.util.List;
     5import java.util.Optional;
    46
    57public interface PostService {
     
    79    void save (Post post);
    810
     11    List<Post> findAll();
     12
     13    Optional<Post> findById(Integer id);
    914}
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/ShelterService.java

    rf194b4e r8b7dd7f  
    44
    55import java.util.List;
     6import java.util.Optional;
    67
    78public interface ShelterService {
     9    Optional<Shelter> findById(Integer id);
    810    List<Shelter> listShelters();
    911}
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/PetServiceImplementation.java

    rf194b4e r8b7dd7f  
    2222    }
    2323
    24     @Override
    2524    public List<Pet> listpets() {return this.petRepository.findAll();}
    2625
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/PostServiceImplementation.java

    rf194b4e r8b7dd7f  
    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/service/implementation/ShelterServiceImplementation.java

    rf194b4e r8b7dd7f  
    77
    88import java.util.List;
     9import java.util.Optional;
    910
    1011@Service
    1112public class ShelterServiceImplementation implements ShelterService {
     13
    1214    private final ShelterRepository shelterRepository;
    1315
     
    1618    }
    1719
     20    @Override
     21    public Optional<Shelter> findById(Integer id) {
     22        return this.shelterRepository.findById(id);
     23    }
    1824
    1925    @Override
     
    2127        return shelterRepository.findAll();
    2228    }
     29
     30
    2331}
  • Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PetController.java

    rf194b4e r8b7dd7f  
    11package finki.paw5.web.controllers;
    22
     3import finki.paw5.model.entities.Adoption;
     4import finki.paw5.model.entities.Pet;
     5import finki.paw5.model.entities.User;
     6import finki.paw5.model.exceptions.InvalidPetIdException;
     7import finki.paw5.service.AdoptionService;
    38import finki.paw5.service.PetService;
     9import jakarta.servlet.http.HttpServletRequest;
    410import org.springframework.stereotype.Controller;
     11import org.springframework.web.bind.annotation.PathVariable;
     12import org.springframework.web.bind.annotation.PostMapping;
     13
     14import java.time.LocalDate;
    515
    616@Controller
     
    818
    919    private final PetService petService;
     20    private final AdoptionService adoptionService;
    1021
    11     public PetController(PetService petService) {
     22    public PetController(PetService petService, AdoptionService adoptionService) {
    1223        this.petService = petService;
     24        this.adoptionService = adoptionService;
    1325    }
    1426
     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    }
    1542}
  • Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PostController.java

    rf194b4e r8b7dd7f  
    11package finki.paw5.web.controllers;
    2 
    3 import finki.paw5.model.entities.Employee;
    42import finki.paw5.model.entities.Pet;
    53import finki.paw5.model.entities.Post;
    6 import finki.paw5.model.entities.User;
     4import finki.paw5.model.entities.Employee;
    75import finki.paw5.model.enumerations.AgeGroup;
    86import finki.paw5.model.enumerations.Gender;
    97import finki.paw5.model.enumerations.Size;
    108import finki.paw5.model.enumerations.Species;
     9import finki.paw5.service.PersonalProfileService;
    1110import finki.paw5.service.PetService;
    1211import finki.paw5.service.PostService;
     12import finki.paw5.service.ShelterService;
    1313import jakarta.servlet.http.HttpServletRequest;
    1414import org.springframework.stereotype.Controller;
    1515import org.springframework.ui.Model;
    1616import org.springframework.web.bind.annotation.GetMapping;
     17import org.springframework.web.bind.annotation.PathVariable;
    1718import org.springframework.web.bind.annotation.PostMapping;
    1819import org.springframework.web.bind.annotation.RequestParam;
    1920
    2021import java.time.LocalDate;
     22import java.util.List;
    2123
    2224@Controller
     
    2527    private final PostService postService;
    2628    private final PetService petService;
     29    private final PersonalProfileService personalProfileService;
    2730
    28     public PostController(PostService postService, PetService petService) {
     31    public PostController(PostService postService, PetService petService, PersonalProfileService personalProfileService, ShelterService shelterService) {
    2932        this.postService = postService;
    3033        this.petService = petService;
     34        this.personalProfileService = personalProfileService;
    3135    }
    3236
     
    7175        return "redirect:/home";
    7276    }
     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    }
    73101}
  • Prototype Application/Paw5/src/main/resources/templates/aboutUs.html

    rf194b4e r8b7dd7f  
    4040    <h5 class="text-center text-danger">
    4141        You successfully logged in
    42         <th:block  th:text="${session.user.getId()}"></th:block>
     42        <th:block  th:text="${session.user?.getId()}"></th:block>
    4343    </h5>
    4444</div>
  • Prototype Application/Paw5/src/main/resources/templates/home.html

    rf194b4e r8b7dd7f  
    3636</header>
    3737<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>
    3844  <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>
    4048  </form>
    4149</div>
    4250<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>
    4756</div>
    48 
    4957</body>
    5058</html>
Note: See TracChangeset for help on using the changeset viewer.