mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-16 12:45:48 +00:00
Added logging to OwnerController for tracking actions
Signed-off-by: PavanKumar <paonejogi.com>
This commit is contained in:
parent
6328d2c9dc
commit
503c1bf81a
1 changed files with 8 additions and 0 deletions
|
@ -18,6 +18,8 @@ package org.springframework.samples.petclinic.owner;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
@ -50,6 +52,8 @@ class OwnerController {
|
||||||
|
|
||||||
private final OwnerRepository owners;
|
private final OwnerRepository owners;
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(OwnerController.class);
|
||||||
|
|
||||||
public OwnerController(OwnerRepository owners) {
|
public OwnerController(OwnerRepository owners) {
|
||||||
this.owners = owners;
|
this.owners = owners;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +85,8 @@ class OwnerController {
|
||||||
|
|
||||||
this.owners.save(owner);
|
this.owners.save(owner);
|
||||||
redirectAttributes.addFlashAttribute("message", "New Owner Created");
|
redirectAttributes.addFlashAttribute("message", "New Owner Created");
|
||||||
|
logger.info("New owner added: {} {}", owner.getFirstName(), owner.getLastName());
|
||||||
|
|
||||||
return "redirect:/owners/" + owner.getId();
|
return "redirect:/owners/" + owner.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,12 +102,14 @@ class OwnerController {
|
||||||
if (owner.getLastName() == null) {
|
if (owner.getLastName() == null) {
|
||||||
owner.setLastName(""); // empty string signifies broadest possible search
|
owner.setLastName(""); // empty string signifies broadest possible search
|
||||||
}
|
}
|
||||||
|
logger.info("Searching for owners with last name: {}", owner.getLastName());
|
||||||
|
|
||||||
// find owners by last name
|
// find owners by last name
|
||||||
Page<Owner> ownersResults = findPaginatedForOwnersLastName(page, owner.getLastName());
|
Page<Owner> ownersResults = findPaginatedForOwnersLastName(page, owner.getLastName());
|
||||||
if (ownersResults.isEmpty()) {
|
if (ownersResults.isEmpty()) {
|
||||||
// no owners found
|
// no owners found
|
||||||
result.rejectValue("lastName", "notFound", "not found");
|
result.rejectValue("lastName", "notFound", "not found");
|
||||||
|
|
||||||
return "owners/findOwners";
|
return "owners/findOwners";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue