mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
handle 'mark as read'
This commit is contained in:
@@ -5,6 +5,7 @@ import java.util.Set;
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
import com.commafeed.frontend.rest.resources.AbstractREST;
|
||||
import com.commafeed.frontend.rest.resources.EntriesREST;
|
||||
import com.commafeed.frontend.rest.resources.SubscriptionsREST;
|
||||
import com.google.common.collect.Sets;
|
||||
@@ -17,6 +18,7 @@ public class RESTApplication extends Application {
|
||||
Set<Class<?>> set = Sets.newHashSet();
|
||||
set.add(JSONMessageBodyWriter.class);
|
||||
|
||||
set.add(AbstractREST.class);
|
||||
set.add(SubscriptionsREST.class);
|
||||
set.add(EntriesREST.class);
|
||||
return set;
|
||||
|
||||
@@ -5,8 +5,10 @@ import javax.inject.Inject;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.apache.wicket.Application;
|
||||
import org.apache.wicket.ThreadContext;
|
||||
@@ -51,6 +53,10 @@ public abstract class AbstractREST {
|
||||
ThreadContext.setRequestCycle(cycle);
|
||||
Application.get().fetchCreateAndSetSession(
|
||||
Application.get().createRequestCycle(swreq, swresp));
|
||||
|
||||
if (getUser() == null) {
|
||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
protected User getUser() {
|
||||
|
||||
@@ -93,4 +93,26 @@ public class EntriesREST extends AbstractREST {
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Path("mark/{type}/{id}/{read}")
|
||||
@GET
|
||||
public void mark(@PathParam("type") String type,
|
||||
@PathParam("id") String id, @PathParam("read") boolean read) {
|
||||
if ("entry".equals(type)) {
|
||||
FeedEntry entry = feedEntryService.findById(Long.valueOf(id));
|
||||
FeedEntryStatus status = feedEntryStatusService.getStatus(
|
||||
getUser(), entry);
|
||||
if (status == null) {
|
||||
status = new FeedEntryStatus();
|
||||
status.setUser(getUser());
|
||||
status.setEntry(entry);
|
||||
}
|
||||
status.setRead(read);
|
||||
if (status.getId() == null) {
|
||||
feedEntryStatusService.save(status);
|
||||
} else {
|
||||
feedEntryStatusService.update(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user