Ignore:
Timestamp:
03/05/23 18:01:28 (16 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.