diff --git a/src/main/java/org/springframework/samples/petclinic/rest/OwnerRestController.java b/src/main/java/org/springframework/samples/petclinic/rest/OwnerRestController.java index 794035708..84e5e297e 100644 --- a/src/main/java/org/springframework/samples/petclinic/rest/OwnerRestController.java +++ b/src/main/java/org/springframework/samples/petclinic/rest/OwnerRestController.java @@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.util.UriComponentsBuilder; @@ -47,16 +48,19 @@ public class OwnerRestController { @Autowired private ClinicService clinicService; - @RequestMapping(value = "/}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getAllOwners(){ - Collection owners = this.clinicService.findOwnerByLastName(""); + @RequestMapping(value = "/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + public ResponseEntity> getOwnersList(@RequestParam("lastName") String ownerLastName){ + if (ownerLastName == null){ + ownerLastName = ""; + } + Collection owners = this.clinicService.findOwnerByLastName(ownerLastName); if(owners.isEmpty()){ return new ResponseEntity>(HttpStatus.NOT_FOUND); } return new ResponseEntity>(owners, HttpStatus.OK); } - @RequestMapping(value = "/{ownerId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/{ownerId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public ResponseEntity getOwner(@PathVariable("ownerId") int ownerId){ Owner owner = this.clinicService.findOwnerById(ownerId); if(owner == null){ @@ -65,18 +69,18 @@ public class OwnerRestController { return new ResponseEntity(owner, HttpStatus.OK); } - @RequestMapping(value = "/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public ResponseEntity addOwner(@RequestBody @Valid Owner owner, BindingResult bindingResult, UriComponentsBuilder ucBuilder){ if(bindingResult.hasErrors() || (owner == null)){ return new ResponseEntity(HttpStatus.BAD_REQUEST); } this.clinicService.saveOwner(owner); HttpHeaders headers = new HttpHeaders(); - headers.setLocation(ucBuilder.path("/owners/{id}").buildAndExpand(owner.getId()).toUri()); + headers.setLocation(ucBuilder.path("/api/owners/{id}").buildAndExpand(owner.getId()).toUri()); return new ResponseEntity(headers, HttpStatus.CREATED); } - @RequestMapping(value = "/{ownerId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/{ownerId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public ResponseEntity updateOwner(@PathVariable("ownerId") int ownerId, @RequestBody @Valid Owner owner, BindingResult bindingResult, UriComponentsBuilder ucBuilder){ if(bindingResult.hasErrors() || (owner == null)){ return new ResponseEntity(HttpStatus.BAD_REQUEST); @@ -91,7 +95,7 @@ public class OwnerRestController { currentOwner.setLastName(owner.getLastName());; currentOwner.setTelephone(owner.getTelephone()); this.clinicService.saveOwner(currentOwner); - return new ResponseEntity(currentOwner, HttpStatus.OK); + return new ResponseEntity(currentOwner, HttpStatus.NO_CONTENT); } diff --git a/src/main/java/org/springframework/samples/petclinic/rest/VetRestController.java b/src/main/java/org/springframework/samples/petclinic/rest/VetRestController.java index 0c8d0694a..67d2099d1 100644 --- a/src/main/java/org/springframework/samples/petclinic/rest/VetRestController.java +++ b/src/main/java/org/springframework/samples/petclinic/rest/VetRestController.java @@ -40,7 +40,7 @@ public class VetRestController { @Autowired private ClinicService clinicService; - @RequestMapping(value = "/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) + @RequestMapping(value = "/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public ResponseEntity> getAllVets(){ Collection vets = new ArrayList(); vets.addAll(this.clinicService.findVets());