toggle between unread and all entries

This commit is contained in:
Athou
2013-03-23 17:56:19 +01:00
parent 84e4751e07
commit 1871fa1169
4 changed files with 38 additions and 12 deletions

View File

@@ -46,12 +46,11 @@ public class FeedEntryService extends GenericDAO<FeedEntry, Long> {
return typedQuery.getResultList();
}
public List<FeedEntry> getAllEntries(Feed feed, User user) {
public List<FeedEntry> getAllEntries(Feed feed) {
String query = "select e from FeedEntry e where e.feed=:feed";
TypedQuery<FeedEntry> typedQuery = em.createQuery(query,
FeedEntry.class);
typedQuery.setParameter("feed", feed);
typedQuery.setParameter("user", user);
return typedQuery.getResultList();
}

View File

@@ -30,11 +30,13 @@ public class EntriesREST extends AbstractREST {
@PathParam("id") String id, @PathParam("readType") String readType) {
Entries entries = new Entries();
boolean unreadOnly = "unread".equals(readType);
if ("feed".equals(type)) {
FeedSubscription subscription = feedSubscriptionService
.findById(Long.valueOf(id));
entries.setName(subscription.getTitle());
entries.getEntries().addAll(buildEntries(subscription));
entries.getEntries().addAll(buildEntries(subscription, unreadOnly));
} else {
FeedCategory feedCategory = "all".equals(id) ? null
@@ -45,7 +47,8 @@ public class EntriesREST extends AbstractREST {
entries.setName("all".equals(id) ? "All" : feedCategory.getName());
for (FeedSubscription subscription : subscriptions) {
entries.getEntries().addAll(buildEntries(subscription));
entries.getEntries().addAll(
buildEntries(subscription, unreadOnly));
}
}
@@ -59,9 +62,17 @@ public class EntriesREST extends AbstractREST {
return entries;
}
private List<Entry> buildEntries(FeedSubscription subscription) {
List<FeedEntry> feedEntries = feedEntryService.getUnreadEntries(
subscription.getFeed(), getUser());
private List<Entry> buildEntries(FeedSubscription subscription,
boolean unreadOnly) {
List<FeedEntry> feedEntries = null;
if (unreadOnly) {
feedEntries = feedEntryService.getUnreadEntries(
subscription.getFeed(), getUser());
} else {
feedEntries = feedEntryService.getAllEntries(
subscription.getFeed());
}
List<Entry> entries = Lists.newArrayList();
for (FeedEntry feedEntry : feedEntries) {