@RequestMapping(
     value = "/{id}/addresses/{address}",
     method = RequestMethod.POST,
     headers = "Accept=application/json")
 @ResponseBody
 @Transactional
 public ResponseEntity<String> addAddressToUser(
     @PathVariable("id") Long userId,
     @PathVariable("address") Long addressId,
     @RequestBody String json) {
   TaskUser taskUser = taskusers.findOne(userId);
   HttpHeaders headers = new HttpHeaders();
   headers.add("Content-Type", "application/json; charset=utf-8");
   if (taskUser == null) {
     return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
   }
   Address possibleAddress = addresses.findOne(addressId);
   if (possibleAddress == null) {
     return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
   }
   taskUser.addAddress(possibleAddress);
   Address foundAddress = addresses.save(possibleAddress);
   taskusers.save(taskUser);
   return new ResponseEntity<String>(foundAddress.toJson(), headers, HttpStatus.CREATED);
 }
Ejemplo n.º 2
0
 /**
  * GET /addresses/{id}
  *
  * <p>Gets the full json for a address.
  *
  * @param id
  * @return json representation of the requested address, or HttpStatus.NOT_FOUND
  */
 @RequestMapping(value = "/{id}", method = RequestMethod.GET, headers = "Accept=application/json")
 @ResponseBody
 public ResponseEntity<String> showJson(@PathVariable("id") Long id) {
   Address address = addresses.findOne(id);
   HttpHeaders headers = new HttpHeaders();
   headers.add("Content-Type", "application/text; charset=utf-8");
   if (address == null) {
     return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
   }
   return new ResponseEntity<String>(address.toJson(), headers, HttpStatus.OK);
 }
Ejemplo n.º 3
0
 /**
  * DELETE /addresses/{id}
  *
  * <p>Deletes an existing address.
  *
  * @param id
  * @return
  */
 @RequestMapping(
     value = "/{id}",
     method = RequestMethod.DELETE,
     headers = "Accept=application/json")
 public ResponseEntity<String> deleteFromJson(@PathVariable("id") Long id) {
   Address address = addresses.findOne(id);
   HttpHeaders headers = new HttpHeaders();
   headers.add("Content-Type", "application/text");
   if (address == null) {
     return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
   }
   addresses.delete(address);
   return new ResponseEntity<String>(headers, HttpStatus.OK);
 }