// 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; }
@RequestMapping(method = GET) public SequencedResources<SubscriptionEntryGetResponse> get( @RequestParam(value = "q", required = false) String q, @RequestParam(value = "feedUuidEqual", required = false) String feedUuidEqual, @RequestParam(value = "seenEqual", required = false) String seenEqual, @RequestParam(value = "feedTagEqual", required = false) String feedTagEqual, @RequestParam(value = "entryTagEqual", required = false) String entryTagEqual, Sequenceable sequenceable, @AuthenticationPrincipal MyReaderUser user) { Slice<SubscriptionEntry> pagedEntries = subscriptionEntryRepository.findBy( q, user.getId(), feedUuidEqual, feedTagEqual, entryTagEqual, seenEqual, sequenceable.getNext(), sequenceable.toPageable()); return resourceAssemblers.toResource( toSequence(sequenceable, pagedEntries.getContent()), SubscriptionEntryGetResponse.class); }
@RequestMapping(value = "availableTags", method = GET) public Set<String> tags(@AuthenticationPrincipal MyReaderUser user) { return subscriptionEntryRepository.findDistinctTags(user.getId()); }