Changes in Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PetController.java [9a180fd:55c0119]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PetController.java
r9a180fd r55c0119 1 1 package finki.paw5.web.controllers; 2 2 3 import finki.paw5.model.entities.Adoption;4 import finki.paw5.model.entities.Pet;5 import finki.paw5.model.entities.User;6 import finki.paw5.model.exceptions.InvalidPetIdException;7 import finki.paw5.service.AdoptionService;8 3 import finki.paw5.service.PetService; 9 import jakarta.servlet.http.HttpServletRequest;10 4 import org.springframework.stereotype.Controller; 11 import org.springframework.web.bind.annotation.PathVariable;12 import org.springframework.web.bind.annotation.PostMapping;13 14 import java.time.LocalDate;15 5 16 6 @Controller … … 18 8 19 9 private final PetService petService; 20 private final AdoptionService adoptionService;21 10 22 public PetController(PetService petService , AdoptionService adoptionService) {11 public PetController(PetService petService) { 23 12 this.petService = petService; 24 this.adoptionService = adoptionService;25 13 } 26 14 27 @PostMapping("/submit-adopton-{id}")28 public String saveAdoption(@PathVariable Integer id, HttpServletRequest request) {29 30 Pet pet = this.petService.findById(id).orElseThrow(InvalidPetIdException::new);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 }42 15 }
Note:
See TracChangeset
for help on using the changeset viewer.