mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
initial starring support
This commit is contained in:
@@ -86,6 +86,28 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
return q.getResultList();
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findStarred(User user, int offset, int limit,
|
||||
ReadingOrder order, boolean includeContent) {
|
||||
|
||||
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
|
||||
Root<FeedEntryStatus> root = query.from(getType());
|
||||
|
||||
List<Predicate> predicates = Lists.newArrayList();
|
||||
predicates.add(builder.equal(root.get(FeedEntryStatus_.subscription)
|
||||
.get(FeedSubscription_.user), user));
|
||||
|
||||
query.where(builder.equal(root.get(FeedEntryStatus_.starred), true));
|
||||
if (includeContent) {
|
||||
root.fetch(FeedEntryStatus_.entry).fetch(FeedEntry_.content);
|
||||
}
|
||||
|
||||
orderBy(query, root, order);
|
||||
|
||||
TypedQuery<FeedEntryStatus> q = em.createQuery(query);
|
||||
limit(q, offset, limit);
|
||||
return q.getResultList();
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findAll(User user, boolean unreadOnly,
|
||||
ReadingOrder order, boolean includeContent) {
|
||||
return findAll(user, unreadOnly, -1, -1, order, includeContent);
|
||||
|
||||
@@ -18,4 +18,10 @@ public class FeedEntryService {
|
||||
status.setRead(read);
|
||||
feedEntryStatusDAO.update(status);
|
||||
}
|
||||
|
||||
public void starEntry(User user, Long entryId, boolean starred) {
|
||||
FeedEntryStatus status = feedEntryStatusDAO.findById(user, entryId);
|
||||
status.setStarred(starred);
|
||||
feedEntryStatusDAO.update(status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.commafeed.frontend.model.request;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.wordnik.swagger.annotations.ApiClass;
|
||||
import com.wordnik.swagger.annotations.ApiProperty;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@ApiClass("Star Request")
|
||||
public class StarRequest implements Serializable {
|
||||
|
||||
@ApiProperty(value = "id", required = true)
|
||||
private String id;
|
||||
|
||||
@ApiProperty(value = "starred or not")
|
||||
private boolean starred;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean isStarred() {
|
||||
return starred;
|
||||
}
|
||||
|
||||
public void setStarred(boolean starred) {
|
||||
this.starred = starred;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,12 +42,13 @@ import com.wordnik.swagger.annotations.ApiParam;
|
||||
public class CategoryREST extends AbstractResourceREST {
|
||||
|
||||
public static final String ALL = "all";
|
||||
public static final String STARRED = "starred";
|
||||
|
||||
@Path("/entries")
|
||||
@GET
|
||||
@ApiOperation(value = "Get category entries", notes = "Get a list of category entries", responseClass = "com.commafeed.frontend.model.Entries")
|
||||
public Entries getCategoryEntries(
|
||||
@ApiParam(value = "id of the category, or 'all'", required = true) @QueryParam("id") String id,
|
||||
@ApiParam(value = "id of the category, 'all' or 'starred'", required = true) @QueryParam("id") String id,
|
||||
@ApiParam(value = "all entries or only unread ones", allowableValues = "all,unread", required = true) @QueryParam("readType") ReadType readType,
|
||||
@ApiParam(value = "offset for paging") @DefaultValue("0") @QueryParam("offset") int offset,
|
||||
@ApiParam(value = "limit for paging") @DefaultValue("-1") @QueryParam("limit") int limit,
|
||||
@@ -67,6 +68,13 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
entries.getEntries().add(Entry.build(status));
|
||||
}
|
||||
|
||||
} else if (STARRED.equals(id)) {
|
||||
entries.setName("Starred");
|
||||
List<FeedEntryStatus> starred = feedEntryStatusDAO.findStarred(
|
||||
getUser(), offset, limit, order, true);
|
||||
for (FeedEntryStatus status : starred) {
|
||||
entries.getEntries().add(Entry.build(status));
|
||||
}
|
||||
} else {
|
||||
FeedCategory feedCategory = feedCategoryDAO.findById(getUser(),
|
||||
Long.valueOf(id));
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.commafeed.backend.model.FeedEntryStatus;
|
||||
import com.commafeed.frontend.model.Entries;
|
||||
import com.commafeed.frontend.model.Entry;
|
||||
import com.commafeed.frontend.model.request.MarkRequest;
|
||||
import com.commafeed.frontend.model.request.StarRequest;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.wordnik.swagger.annotations.Api;
|
||||
@@ -40,6 +41,20 @@ public class EntryREST extends AbstractResourceREST {
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@Path("/star")
|
||||
@POST
|
||||
@ApiOperation(value = "Mark a feed entry", notes = "Mark a feed entry as read/unread")
|
||||
public Response starFeedEntry(
|
||||
@ApiParam(value = "Star Request", required = true) StarRequest req) {
|
||||
Preconditions.checkNotNull(req);
|
||||
Preconditions.checkNotNull(req.getId());
|
||||
|
||||
feedEntryService.starEntry(getUser(), Long.valueOf(req.getId()),
|
||||
req.isStarred());
|
||||
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@Path("/search")
|
||||
@GET
|
||||
@ApiOperation(value = "Search for entries", notes = "Look through title and content of entries by keywords", responseClass = "com.commafeed.frontend.model.Entries")
|
||||
|
||||
Reference in New Issue
Block a user