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

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