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