1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

Improve feed and user API updates with optional values

This commit is contained in:
Frédéric Guillot 2018-06-23 16:16:54 -07:00
parent cd77ebd742
commit 7039df9af1
12 changed files with 685 additions and 508 deletions

View file

@ -97,7 +97,7 @@ func (c *Controller) UpdateFeed(w http.ResponseWriter, r *http.Request) {
return
}
newFeed, err := decodeFeedModificationPayload(r.Body)
feedChanges, err := decodeFeedModificationPayload(r.Body)
if err != nil {
json.BadRequest(w, err)
return
@ -106,11 +106,6 @@ func (c *Controller) UpdateFeed(w http.ResponseWriter, r *http.Request) {
ctx := context.New(r)
userID := ctx.UserID()
if newFeed.Category != nil && newFeed.Category.ID != 0 && !c.store.CategoryExists(userID, newFeed.Category.ID) {
json.BadRequest(w, 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 {
json.NotFound(w, errors.New("Unable to find this feed"))
@ -122,7 +117,13 @@ func (c *Controller) UpdateFeed(w http.ResponseWriter, r *http.Request) {
return
}
originalFeed.Merge(newFeed)
feedChanges.Update(originalFeed)
if !c.store.CategoryExists(userID, originalFeed.Category.ID) {
json.BadRequest(w, errors.New("This category_id doesn't exists or doesn't belongs to this user"))
return
}
if err := c.store.UpdateFeed(originalFeed); err != nil {
json.ServerError(w, errors.New("Unable to update this feed"))
return