/** * Custom handler for displaying an owner. * * @param ownerId the ID of the owner to display * @return a ModelMap with the model attributes for the view */ @GetMapping("/owners/{ownerId}") public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { ModelAndView mav = new ModelAndView("owners/ownerDetails"); mav.addObject(this.owners.findById(ownerId)); return mav; }
@ModelAttribute("owner") public Owner findOwner(@PathVariable("ownerId") int ownerId) { return this.owners.findById(ownerId); }
@GetMapping("/owners/{ownerId}/edit") public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { Owner owner = this.owners.findById(ownerId); model.addAttribute(owner); return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; }
@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.GET) public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { Owner owner = this.owners.findById(ownerId); model.addAttribute(owner); return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; }
@ModelAttribute("owner") public Owner findOwner(@PathVariable("ownerId") int ownerId) { return this.owners.findById(ownerId); }
/** * Custom handler for displaying an owner. * * @param ownerId the ID of the owner to display * @return a ModelMap with the model attributes for the view */ @RequestMapping("/owners/{ownerId}") public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { ModelAndView mav = new ModelAndView("owners/ownerDetails"); mav.addObject(this.owners.findById(ownerId)); return mav; }
@RequestMapping(value = "/owner/{ownerId}/getVisits", method = RequestMethod.GET) public ResponseEntity<List<Visit>> getOwnerVisits(@PathVariable int ownerId){ List<Pet> petList = this.owners.findById(ownerId).getPets(); List<Visit> visitList = new ArrayList<Visit>(); petList.forEach(pet -> visitList.addAll(pet.getVisits())); return new ResponseEntity<List<Visit>>(visitList, HttpStatus.OK); } }