ability to subscribe to a feed

This commit is contained in:
Athou
2013-03-24 13:11:05 +01:00
parent 17fe01ade4
commit fb40ced8a1
16 changed files with 828 additions and 9 deletions

View File

@@ -1,10 +1,18 @@
package com.commafeed.backend.dao;
import java.util.List;
import javax.ejb.Stateless;
import com.commafeed.backend.model.Feed;
import com.commafeed.frontend.utils.ModelFactory.MF;
import com.google.common.collect.Iterables;
@Stateless
public class FeedService extends GenericDAO<Feed, Long> {
public Feed findByUrl(String url) {
List<Feed> feeds = findByField(MF.i(proxy().getUrl()), url);
return Iterables.getFirst(feeds, null);
}
}

View File

@@ -56,7 +56,7 @@ public abstract class GenericDAO<T, K> implements
em.remove(object);
}
public void deleteById(Object id) {
public void deleteById(K id) {
Object ref = em.getReference(getType(), id);
em.remove(ref);
}

View File

@@ -0,0 +1,35 @@
package com.commafeed.frontend.model;
import java.io.Serializable;
public class SubscriptionRequest implements Serializable {
private String url;
private String title;
private String categoryId;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
}

View File

@@ -5,16 +5,18 @@
<link href="vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="vendor/angular-ui/angular-ui.min.css" rel="stylesheet">
<link href="vendor/csstreeview/css3-treeview.css" rel="stylesheet">
<link href="vendor/select2/select2.css" rel="stylesheet">
<link href="css/app.css" rel="stylesheet">
</head>
<body>
<div ng-app="commafeed">
<div class="container-fluid">
<div class="row-fluid">
<div class="span2" ng-controller="CategoryTreeCtrl">
<div class="css-treeview">
<div class="span2">
<subscribe></subscribe>
<div class="css-treeview" ng-controller="CategoryTreeCtrl">
<ul>
<category node="root" feed-click="feedClicked(id)"
<category node="SubscriptionService.subscriptions" feed-click="feedClicked(id)"
category-click="categoryClicked(id)" selected-type="selectedType"
selected-id="selectedId"
format-category-name="formatCategoryName(category)"
@@ -32,6 +34,7 @@
<script src="vendor/jquery/jquery-1.9.1.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="vendor/select2/select2.min.js"></script>
<script src="vendor/angular/angular.min.js"></script>
<script src="vendor/angular/angular-resource.min.js"></script>
<script src="vendor/angular/angular-sanitize.min.js"></script>

View File

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

View File

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

View File

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