mark all as read for categories

This commit is contained in:
Jeremie Panzer
2013-03-27 12:31:12 +01:00
parent 473800d2f6
commit 1515eec5e7

View File

@@ -149,13 +149,26 @@ public class EntriesREST extends AbstractREST {
} else if (type == Type.feed) {
Feed feed = feedSubscriptionService.findById(Long.valueOf(id))
.getFeed();
if (read) {
List<FeedEntryWithStatus> entries = feedEntryService
.getEntries(feed, getUser(), false);
for (FeedEntryWithStatus entry : entries) {
markEntry(entry.getEntry(), true);
}
List<FeedEntryWithStatus> entries = feedEntryService.getEntries(
feed, getUser(), false);
for (FeedEntryWithStatus entry : entries) {
markEntry(entry, read);
}
} else if (type == Type.category) {
FeedCategory feedCategory = null;
if (!ALL.equals(id)) {
feedCategory = feedCategoryService.findById(getUser(),
Long.valueOf(id));
}
List<FeedCategory> childrenCategories = feedCategoryService
.findAllChildrenCategories(getUser(), feedCategory);
List<FeedEntryWithStatus> entries = feedEntryService.getEntries(
childrenCategories, getUser(), false);
for (FeedEntryWithStatus entry : entries) {
markEntry(entry, true);
}
}
return Response.ok(Status.OK).build();
}
@@ -172,4 +185,15 @@ public class EntriesREST extends AbstractREST {
feedEntryStatusService.saveOrUpdate(status);
}
private void markEntry(FeedEntryWithStatus entryWithStatus, boolean read) {
FeedEntryStatus status = entryWithStatus.getStatus();
if (status == null) {
status = new FeedEntryStatus();
status.setUser(getUser());
status.setEntry(entryWithStatus.getEntry());
}
status.setRead(read);
feedEntryStatusService.saveOrUpdate(status);
}
}