aboutsummaryrefslogtreecommitdiff
path: root/server/api/controller/feed.go
diff options
context:
space:
mode:
Diffstat (limited to 'server/api/controller/feed.go')
-rw-r--r--server/api/controller/feed.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/server/api/controller/feed.go b/server/api/controller/feed.go
index f0212c97..fcaeee78 100644
--- a/server/api/controller/feed.go
+++ b/server/api/controller/feed.go
@@ -20,6 +20,26 @@ func (c *Controller) CreateFeed(ctx *core.Context, request *core.Request, respon
return
}
+ if feedURL == "" {
+ response.JSON().BadRequest(errors.New("The feed_url is required"))
+ return
+ }
+
+ if categoryID <= 0 {
+ response.JSON().BadRequest(errors.New("The category_id is required"))
+ return
+ }
+
+ if c.store.FeedURLExists(userID, feedURL) {
+ response.JSON().BadRequest(errors.New("This feed_url already exists"))
+ return
+ }
+
+ if !c.store.CategoryExists(userID, categoryID) {
+ response.JSON().BadRequest(errors.New("This category_id doesn't exists or doesn't belongs to this user"))
+ return
+ }
+
feed, err := c.feedHandler.CreateFeed(userID, categoryID, feedURL, false)
if err != nil {
response.JSON().ServerError(errors.New("Unable to create this feed"))
@@ -42,6 +62,11 @@ func (c *Controller) RefreshFeed(ctx *core.Context, request *core.Request, respo
return
}
+ if !c.store.FeedExists(userID, feedID) {
+ response.JSON().NotFound(errors.New("Unable to find this feed"))
+ return
+ }
+
err = c.feedHandler.RefreshFeed(userID, feedID)
if err != nil {
response.JSON().ServerError(errors.New("Unable to refresh this feed"))
@@ -66,6 +91,11 @@ func (c *Controller) UpdateFeed(ctx *core.Context, request *core.Request, respon
return
}
+ if newFeed.Category != nil && newFeed.Category.ID != 0 && !c.store.CategoryExists(userID, newFeed.Category.ID) {
+ response.JSON().BadRequest(errors.New("This category_id doesn't exists or doesn't belongs to this user"))
+ return
+ }
+
originalFeed, err := c.store.FeedByID(userID, feedID)
if err != nil {
response.JSON().NotFound(errors.New("Unable to find this feed"))
@@ -83,6 +113,12 @@ func (c *Controller) UpdateFeed(ctx *core.Context, request *core.Request, respon
return
}
+ originalFeed, err = c.store.FeedByID(userID, feedID)
+ if err != nil {
+ response.JSON().ServerError(errors.New("Unable to fetch this feed"))
+ return
+ }
+
response.JSON().Created(originalFeed)
}