source: Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PetController.java

main
Last change on this file was e76c5a6, checked in by SazdovaEkaterina <sazdovaekaterina@…>, 16 months ago

fix usages that got broken with the changes

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[4885da3]1package finki.paw5.web.controllers;
2
[e76c5a6]3import finki.paw5.model.entities.Adopter;
[9a180fd]4import finki.paw5.model.entities.Adoption;
5import finki.paw5.model.entities.Pet;
6import finki.paw5.service.AdoptionService;
[4885da3]7import finki.paw5.service.PetService;
[9a180fd]8import jakarta.servlet.http.HttpServletRequest;
[4885da3]9import org.springframework.stereotype.Controller;
[9a180fd]10import org.springframework.web.bind.annotation.PathVariable;
11import org.springframework.web.bind.annotation.PostMapping;
12
13import java.time.LocalDate;
[4885da3]14
15@Controller
16public class PetController {
17
18 private final PetService petService;
[9a180fd]19 private final AdoptionService adoptionService;
[4885da3]20
[9a180fd]21 public PetController(PetService petService, AdoptionService adoptionService) {
[4885da3]22 this.petService = petService;
[9a180fd]23 this.adoptionService = adoptionService;
[4885da3]24 }
25
[e76c5a6]26 @PostMapping("/submit-adoption-{id}")
[9a180fd]27 public String saveAdoption(@PathVariable Integer id, HttpServletRequest request) {
28
[eac569a]29 Pet pet = this.petService.findById(id);
[9a180fd]30
[e76c5a6]31 Adopter adopter = (Adopter) request.getSession().getAttribute("user");
[9a180fd]32
[e76c5a6]33 Adoption adoption = new Adoption(LocalDate.now(), null, false, adopter);
[9a180fd]34 this.adoptionService.save(adoption);
35
[e76c5a6]36 pet.setAdoption(adoption);
[9a180fd]37 this.petService.save(pet);
38
39 return "redirect:/home";
40 }
[4885da3]41}
Note: See TracBrowser for help on using the repository browser.