Example #1
0
 private Feed findOrThrowException(Long id) {
   Feed feed = feedRepository.findOne(id);
   if (feed == null) {
     throw new ResourceNotFoundException();
   }
   return feed;
 }
Example #2
0
  @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();
  }
Example #3
0
 @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);
 }
Example #4
0
 @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();
   }
 }