// 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); }
@ModelAttribute("subscription") Subscription model(@PathVariable("id") Long id, @AuthenticationPrincipal MyReaderUser user) { Subscription subscription = subscriptionRepository.findByIdAndUsername(id, user.getUsername()); if (subscription == null) { throw new ResourceNotFoundException(); } return subscription; }