mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
ability to subscribe to a feed
This commit is contained in:
@@ -20,6 +20,7 @@ import org.apache.wicket.request.cycle.RequestCycle;
|
||||
import com.commafeed.backend.dao.FeedCategoryService;
|
||||
import com.commafeed.backend.dao.FeedEntryService;
|
||||
import com.commafeed.backend.dao.FeedEntryStatusService;
|
||||
import com.commafeed.backend.dao.FeedService;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionService;
|
||||
import com.commafeed.backend.dao.UserService;
|
||||
import com.commafeed.backend.dao.UserSettingsService;
|
||||
@@ -37,6 +38,9 @@ public abstract class AbstractREST {
|
||||
@Context
|
||||
HttpServletResponse response;
|
||||
|
||||
@Inject
|
||||
FeedService feedService;
|
||||
|
||||
@Inject
|
||||
FeedSubscriptionService feedSubscriptionService;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import javax.ws.rs.core.Response.Status;
|
||||
import com.commafeed.backend.model.UserSettings;
|
||||
import com.commafeed.backend.model.UserSettings.ReadingMode;
|
||||
import com.commafeed.frontend.model.Settings;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
@Path("settings")
|
||||
public class SettingsREST extends AbstractREST {
|
||||
@@ -29,6 +30,8 @@ public class SettingsREST extends AbstractREST {
|
||||
@Path("save")
|
||||
@POST
|
||||
public Response save(Settings settings) {
|
||||
Preconditions.checkNotNull(settings);
|
||||
|
||||
UserSettings s = userSettingsService.findByUser(getUser());
|
||||
if (s == null) {
|
||||
s = new UserSettings();
|
||||
|
||||
@@ -3,18 +3,53 @@ package com.commafeed.frontend.rest.resources;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.QueryParam;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedCategory;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.frontend.model.Category;
|
||||
import com.commafeed.frontend.model.Subscription;
|
||||
import com.commafeed.frontend.model.SubscriptionRequest;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
@Path("subscriptions")
|
||||
public class SubscriptionsREST extends AbstractREST {
|
||||
|
||||
@POST
|
||||
@Path("subscribe")
|
||||
public void subscribe(SubscriptionRequest req) {
|
||||
Preconditions.checkNotNull(req);
|
||||
Preconditions.checkNotNull(req.getTitle());
|
||||
Preconditions.checkNotNull(req.getUrl());
|
||||
|
||||
Feed feed = feedService.findByUrl(req.getUrl());
|
||||
if (feed == null) {
|
||||
feed = new Feed();
|
||||
feed.setUrl(req.getUrl());
|
||||
feedService.save(feed);
|
||||
}
|
||||
|
||||
FeedSubscription sub = new FeedSubscription();
|
||||
sub.setCategory("all".equals(req.getCategoryId()) ? null
|
||||
: feedCategoryService.findById(Long.valueOf(req.getCategoryId())));
|
||||
sub.setFeed(feed);
|
||||
sub.setTitle(req.getTitle());
|
||||
sub.setUser(getUser());
|
||||
feedSubscriptionService.save(sub);
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("unsubscribe")
|
||||
public void unsubscribe(@QueryParam("id") Long subscriptionId) {
|
||||
feedSubscriptionService.deleteById(subscriptionId);
|
||||
}
|
||||
|
||||
@GET
|
||||
public Category getSubscriptions() {
|
||||
Category root = new Category();
|
||||
|
||||
Reference in New Issue
Block a user