handle 'mark as read'

This commit is contained in:
Athou
2013-03-23 17:17:27 +01:00
parent 4df1e7f722
commit 84e4751e07
8 changed files with 90 additions and 47 deletions

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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);
}
}
}
}