예제 #1
0
 @Transactional
 @ResponseBody
 @RequestMapping(value = "/api/drug", method = RequestMethod.POST, consumes = "application/json")
 public ResponseEntity<?> create(@RequestBody DrugResource drugResource) {
   Long loggedInUserProfileId = securityController.getAuthenticatedUserProfileId();
   if (loggedInUserProfileId != null
       && loggedInUserProfileId != UserProfileResource.ANONYMOUS_USER_PROFILE_ID) {
     Drug drug = drugResourceToDomainConverter.convert(drugResource);
     entityManager.persist(drug);
     HttpHeaders httpHeaders = new HttpHeaders();
     httpHeaders.setLocation(linkTo(methodOn(DrugController.class).get(drug.getId())).toUri());
     return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
   } else {
     return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
   }
 }
예제 #2
0
 @Transactional
 @ResponseBody
 @RequestMapping(
     value = "/drug/{id}",
     method = RequestMethod.DELETE,
     consumes = "application/json")
 public ResponseEntity<?> delete(@PathVariable("id") Long id) {
   Long loggedInUserProfileId = securityController.getAuthenticatedUserProfileId();
   if (loggedInUserProfileId != null
       && loggedInUserProfileId != UserProfileResource.ANONYMOUS_USER_PROFILE_ID) {
     Drug drug = entityManager.find(Drug.class, id);
     entityManager.remove(drug);
     return new ResponseEntity<>(HttpStatus.OK);
   } else {
     return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
   }
 }