Skip to content

Commit

Permalink
Merge pull request spring-petclinic#4 from arey/feature/api-pettypes
Browse files Browse the repository at this point in the history
Fix GET /api/pets/pettypes endpoint
  • Loading branch information
vfedoriv authored Feb 23, 2017
2 parents 78d089f + 52b51fd commit 862c02e
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
@CrossOrigin(exposedHeaders = "errors, content-type")
@RequestMapping("api/pets")
public class PetRestController {

@Autowired
private ClinicServiceExt clinicService;

@RequestMapping(value = "/{petId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Pet> getPet(@PathVariable("petId") int petId){
Pet pet = this.clinicService.findPetById(petId);
Expand All @@ -59,7 +59,7 @@ public ResponseEntity<Pet> getPet(@PathVariable("petId") int petId){
}
return new ResponseEntity<Pet>(pet, HttpStatus.OK);
}

@RequestMapping(value = "", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Collection<Pet>> getPets(){
Collection<Pet> pets = this.clinicService.findAllPets();
Expand All @@ -68,12 +68,12 @@ public ResponseEntity<Collection<Pet>> getPets(){
}
return new ResponseEntity<Collection<Pet>>(pets, HttpStatus.OK);
}
@RequestMapping(value = "/pettypes}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)

@RequestMapping(value = "/pettypes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Collection<PetType>> getPetTypes(){
return new ResponseEntity<Collection<PetType>>(this.clinicService.findPetTypes(), HttpStatus.OK);
}

@RequestMapping(value = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Pet> addPet(@RequestBody @Valid Pet pet, BindingResult bindingResult, UriComponentsBuilder ucBuilder){
BindingErrorsResponse errors = new BindingErrorsResponse();
Expand All @@ -87,7 +87,7 @@ public ResponseEntity<Pet> addPet(@RequestBody @Valid Pet pet, BindingResult bin
headers.setLocation(ucBuilder.path("/api/pets/{id}").buildAndExpand(pet.getId()).toUri());
return new ResponseEntity<Pet>(pet, headers, HttpStatus.CREATED);
}

@RequestMapping(value = "/{petId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Pet> updatePet(@PathVariable("petId") int petId, @RequestBody @Valid Pet pet, BindingResult bindingResult){
BindingErrorsResponse errors = new BindingErrorsResponse();
Expand All @@ -108,7 +108,7 @@ public ResponseEntity<Pet> updatePet(@PathVariable("petId") int petId, @RequestB
this.clinicService.savePet(currentPet);
return new ResponseEntity<Pet>(currentPet, HttpStatus.NO_CONTENT);
}

@RequestMapping(value = "/{petId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Transactional
public ResponseEntity<Void> deletePet(@PathVariable("petId") int petId){
Expand All @@ -119,6 +119,6 @@ public ResponseEntity<Void> deletePet(@PathVariable("petId") int petId){
this.clinicService.deletePet(pet);
return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
}


}

0 comments on commit 862c02e

Please sign in to comment.