Browse Source

models, graph2: Added comment removal on chapter removal.

module-madness-pointers
Gisle Aune 6 years ago
parent
commit
39a4fef506
  1. 6
      graph2/queries/chapter.go
  2. 17
      models/comments/remove.go

6
graph2/queries/chapter.go

@ -7,6 +7,7 @@ import (
"git.aiterp.net/rpdata/api/models/changekeys" "git.aiterp.net/rpdata/api/models/changekeys"
"git.aiterp.net/rpdata/api/models/changes" "git.aiterp.net/rpdata/api/models/changes"
"git.aiterp.net/rpdata/api/models/comments"
"git.aiterp.net/rpdata/api/internal/auth" "git.aiterp.net/rpdata/api/internal/auth"
"git.aiterp.net/rpdata/api/models/stories" "git.aiterp.net/rpdata/api/models/stories"
@ -155,6 +156,11 @@ func (r *mutationResolver) RemoveChapter(ctx context.Context, input input.Chapte
return models.Chapter{}, errors.New("Failed to remove chapter: " + err.Error()) return models.Chapter{}, errors.New("Failed to remove chapter: " + err.Error())
} }
err = comments.RemoveChapter(chapter)
if err != nil {
return models.Chapter{}, errors.New("Chapter was removed, but comment removal failed: " + err.Error())
}
go func() { go func() {
story, err := stories.FindID(chapter.StoryID) story, err := stories.FindID(chapter.StoryID)
if err != nil { if err != nil {

17
models/comments/remove.go

@ -0,0 +1,17 @@
package comments
import (
"git.aiterp.net/rpdata/api/models"
"github.com/globalsign/mgo/bson"
)
// Remove removes one comment.
func Remove(comment models.Comment) error {
return collection.RemoveId(comment.ID)
}
// RemoveChapter removes all comments for the given chapter.
func RemoveChapter(chapter models.Chapter) error {
_, err := collection.RemoveAll(bson.M{"chapterId": chapter.ID})
return err
}
Loading…
Cancel
Save