private Feed findOrThrowException(Long id) { Feed feed = feedRepository.findOne(id); if (feed == null) { throw new ResourceNotFoundException(); } return feed; }
@PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "", method = DELETE) public ResponseEntity<Void> delete(@PathVariable("id") Long id) { int count = subscriptionRepository.countByFeedId(id); if (count > 0) { return ResponseEntity.status(HttpStatus.CONFLICT).build(); } if (!feedRepository.exists(id)) { return ResponseEntity.notFound().build(); } feedRepository.delete(id); return ResponseEntity.noContent().build(); }
@PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "", method = RequestMethod.PATCH) public FeedGetResponse patch( @PathVariable("id") Long id, @Valid @RequestBody FeedPatchRequest request) { Feed feed = findOrThrowException(id); Feed patchedFeed = patchService.patch(request, feed); feedRepository.save(patchedFeed); return get(id); }
@RequestMapping(value = "", method = GET) public FeedGetResponse get(@PathVariable("id") Long id) { Feed feed = feedRepository.findOne(id); if (feed != null) { return resourceAssemblers.toResource(feed, FeedGetResponse.class); } else { return new FeedGetResponse(); } }