// TODO remove RequestMethod.PUT after Android 2.x phased out
  @Transactional
  @RequestMapping(method = {RequestMethod.PATCH, RequestMethod.PUT})
  public Resources<SubscriptionEntryGetResponse> patch(
      @Valid @RequestBody SubscriptionEntryBatchPatchRequest request,
      @AuthenticationPrincipal MyReaderUser user) {
    List<SubscriptionEntryGetResponse> subscriptionEntryGetResponses = new ArrayList<>();

    for (final SubscriptionEntryPatchRequest subscriptionPatch : request.getContent()) {
      SubscriptionEntry subscriptionEntry =
          subscriptionEntryRepository.findByIdAndUsername(
              Long.valueOf(subscriptionPatch.getUuid()), user.getUsername());
      if (subscriptionEntry == null) {
        continue;
      }

      if (subscriptionPatch.isFieldPatched("seen")) {
        if (subscriptionPatch.getSeen() != subscriptionEntry.isSeen()) {
          if (subscriptionPatch.getSeen()) {
            subscriptionRepository.decrementUnseen(subscriptionEntry.getSubscription().getId());
          } else {
            subscriptionRepository.incrementUnseen(subscriptionEntry.getSubscription().getId());
          }
        }
      }

      SubscriptionEntry patched = patchService.patch(subscriptionPatch, subscriptionEntry);
      SubscriptionEntry saved = subscriptionEntryRepository.save(patched);
      SubscriptionEntryGetResponse subscriptionEntryGetResponse =
          resourceAssemblers.toResource(saved, SubscriptionEntryGetResponse.class);
      subscriptionEntryGetResponses.add(subscriptionEntryGetResponse);
    }

    return new Resources<>(subscriptionEntryGetResponses);
  }
Example #2
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);
 }
  @Transactional
  @RequestMapping(method = PATCH)
  public SubscriptionEntryGetResponse patch(
      @PathVariable("id") Long id, @RequestBody SubscriptionEntryPatchRequest request) {
    final SubscriptionEntry subscriptionEntry = findOrThrowException(id);

    if (request.isFieldPatched("seen") && request.getSeen() != subscriptionEntry.isSeen()) {
      if (request.getSeen()) {
        subscriptionRepository.decrementUnseen(subscriptionEntry.getSubscription().getId());
      } else {
        subscriptionRepository.incrementUnseen(subscriptionEntry.getSubscription().getId());
      }
    }

    SubscriptionEntry patched = patchService.patch(request, subscriptionEntry);
    subscriptionEntryRepository.save(patched);

    return get(id);
  }