Browse Source

graph2: Added removal of chapters upon story being deleted.

1.0
Gisle Aune 6 years ago
parent
commit
815f30597e
  1. 13
      graph2/queries/story.go
  2. 14
      models/chapters/remove.go

13
graph2/queries/story.go

@ -8,6 +8,7 @@ import (
"git.aiterp.net/rpdata/api/graph2/input" "git.aiterp.net/rpdata/api/graph2/input"
"git.aiterp.net/rpdata/api/internal/auth" "git.aiterp.net/rpdata/api/internal/auth"
"git.aiterp.net/rpdata/api/models" "git.aiterp.net/rpdata/api/models"
"git.aiterp.net/rpdata/api/models/chapters"
"git.aiterp.net/rpdata/api/models/stories" "git.aiterp.net/rpdata/api/models/stories"
) )
@ -121,5 +122,15 @@ func (r *mutationResolver) RemoveStory(ctx context.Context, input input.StoryRem
return models.Story{}, errors.New("You are not permitted to remove this story") return models.Story{}, errors.New("You are not permitted to remove this story")
} }
return stories.Remove(story)
story, err = stories.Remove(story)
if err != nil {
return models.Story{}, err
}
err = chapters.RemoveStory(story)
if err != nil {
return models.Story{}, errors.New("Failed to remove chapters, but story is removed: " + err.Error())
}
return story, nil
} }

14
models/chapters/remove.go

@ -1,6 +1,9 @@
package chapters package chapters
import "git.aiterp.net/rpdata/api/models"
import (
"git.aiterp.net/rpdata/api/models"
"github.com/globalsign/mgo/bson"
)
// Remove removes a chapter. // Remove removes a chapter.
func Remove(chapter models.Chapter) (models.Chapter, error) { func Remove(chapter models.Chapter) (models.Chapter, error) {
@ -10,3 +13,12 @@ func Remove(chapter models.Chapter) (models.Chapter, error) {
return chapter, nil return chapter, nil
} }
// RemoveStory removes all chapters belonging to a story
func RemoveStory(story models.Story) error {
if _, err := collection.RemoveAll(bson.M{"storyId": story.ID}); err != nil {
return err
}
return nil
}
Loading…
Cancel
Save