new frontend model class instead of using the backend feed model

This commit is contained in:
Athou
2013-04-25 13:14:56 +02:00
parent 98d73ab747
commit 8944687006
2 changed files with 51 additions and 10 deletions

View File

@@ -0,0 +1,36 @@
package com.commafeed.frontend.model;
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;
@SuppressWarnings("serial")
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@ApiClass("Feed details")
public class FeedInfo implements Serializable {
private String url;
private String title;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}

View File

@@ -22,17 +22,18 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import com.commafeed.backend.model.Feed; import com.commafeed.backend.feeds.FetchedFeed;
import com.commafeed.backend.model.FeedCategory; import com.commafeed.backend.model.FeedCategory;
import com.commafeed.backend.model.FeedEntryStatus; import com.commafeed.backend.model.FeedEntryStatus;
import com.commafeed.backend.model.FeedSubscription; import com.commafeed.backend.model.FeedSubscription;
import com.commafeed.backend.model.UserSettings.ReadingOrder; import com.commafeed.backend.model.UserSettings.ReadingOrder;
import com.commafeed.frontend.model.Entries; import com.commafeed.frontend.model.Entries;
import com.commafeed.frontend.model.Entry; import com.commafeed.frontend.model.Entry;
import com.commafeed.frontend.model.FeedInfo;
import com.commafeed.frontend.model.request.IDRequest;
import com.commafeed.frontend.model.request.MarkRequest; import com.commafeed.frontend.model.request.MarkRequest;
import com.commafeed.frontend.model.request.RenameRequest; import com.commafeed.frontend.model.request.RenameRequest;
import com.commafeed.frontend.model.request.SubscribeRequest; import com.commafeed.frontend.model.request.SubscribeRequest;
import com.commafeed.frontend.model.request.IDRequest;
import com.commafeed.frontend.rest.Enums.ReadType; import com.commafeed.frontend.rest.Enums.ReadType;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.wordnik.swagger.annotations.Api; import com.wordnik.swagger.annotations.Api;
@@ -81,20 +82,25 @@ public class FeedREST extends AbstractResourceREST {
@GET @GET
@Path("/fetch") @Path("/fetch")
@ApiOperation(value = "Fetch a feed", notes = "Fetch a feed by its url", responseClass = "com.commafeed.backend.model.Feed") @ApiOperation(value = "Fetch a feed", notes = "Fetch a feed by its url", responseClass = "com.commafeed.backend.model.Feed")
public Feed fetchFeed( public FeedInfo fetchFeed(
@ApiParam(value = "the feed's url", required = true) @QueryParam("url") String url) { @ApiParam(value = "the feed's url", required = true) @QueryParam("url") String url) {
Preconditions.checkNotNull(url); Preconditions.checkNotNull(url);
FeedInfo info = null;
url = StringUtils.trimToEmpty(url); url = StringUtils.trimToEmpty(url);
url = prependHttp(url); url = prependHttp(url);
Feed feed = null;
try { try {
feed = feedFetcher.fetch(url, true, null, null).getFeed(); FetchedFeed feed = feedFetcher.fetch(url, true, null, null);
info = new FeedInfo();
info.setUrl(feed.getFeed().getUrl());
info.setTitle(feed.getTitle());
} catch (Exception e) { } catch (Exception e) {
throw new WebApplicationException(e, Response throw new WebApplicationException(e, Response
.status(Status.INTERNAL_SERVER_ERROR) .status(Status.INTERNAL_SERVER_ERROR)
.entity(e.getMessage()).build()); .entity(e.getMessage()).build());
} }
return feed; return info;
} }
@Path("/mark") @Path("/mark")
@@ -130,8 +136,8 @@ public class FeedREST extends AbstractResourceREST {
FeedCategory category = CategoryREST.ALL.equals(req.getCategoryId()) ? null FeedCategory category = CategoryREST.ALL.equals(req.getCategoryId()) ? null
: feedCategoryDAO.findById(Long.valueOf(req.getCategoryId())); : feedCategoryDAO.findById(Long.valueOf(req.getCategoryId()));
Feed fetchedFeed = fetchFeed(url); FeedInfo info = fetchFeed(url);
feedSubscriptionService.subscribe(getUser(), fetchedFeed.getUrl(), feedSubscriptionService.subscribe(getUser(), info.getUrl(),
req.getTitle(), category); req.getTitle(), category);
return Response.ok(Status.OK).build(); return Response.ok(Status.OK).build();
@@ -147,8 +153,7 @@ public class FeedREST extends AbstractResourceREST {
@POST @POST
@Path("/unsubscribe") @Path("/unsubscribe")
@ApiOperation(value = "Unsubscribe to a feed", notes = "Unsubscribe to a feed") @ApiOperation(value = "Unsubscribe to a feed", notes = "Unsubscribe to a feed")
public Response unsubscribe( public Response unsubscribe(@ApiParam(required = true) IDRequest req) {
@ApiParam(required = true) IDRequest req) {
Preconditions.checkNotNull(req); Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId()); Preconditions.checkNotNull(req.getId());