From db4d46c3686f7b56dbeb8046b7f950fd94b86d15 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Sun, 17 Mar 2019 20:44:30 +0100 Subject: [PATCH] Added story to comment changes. --- graph2/queries/comment.go | 33 +++++++++++++++++++++++++++++++-- graph2/schema/types/Comment.gql | 3 +++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/graph2/queries/comment.go b/graph2/queries/comment.go index c37d948..421335a 100644 --- a/graph2/queries/comment.go +++ b/graph2/queries/comment.go @@ -3,8 +3,11 @@ package queries import ( "context" "errors" + "log" "time" + "git.aiterp.net/rpdata/api/models/stories" + "git.aiterp.net/rpdata/api/models/characters" "git.aiterp.net/rpdata/api/models/changekeys" @@ -69,7 +72,15 @@ func (r *mutationResolver) AddComment(ctx context.Context, input input.CommentAd return models.Comment{}, errors.New("Failed to add comment: " + err.Error()) } - go changes.Submit("Comment", "add", token.UserID, true, changekeys.Many(comment, chapter, models.Story{ID: chapter.StoryID}), comment, chapter) + go func() { + story, err := stories.FindID(chapter.StoryID) + if err != nil { + log.Println("WARNING: Couldn't log comment change:", err) + return + } + + changes.Submit("Comment", "add", token.UserID, true, changekeys.Many(comment, chapter, models.Story{ID: chapter.StoryID}), comment, chapter, story) + }() return comment, nil } @@ -112,7 +123,15 @@ func (r *mutationResolver) EditComment(ctx context.Context, input input.CommentE return models.Comment{}, errors.New("Could not post comment: " + err.Error()) } - go changes.Submit("Comment", "edit", token.UserID, true, changekeys.Many(comment, chapter, models.Story{ID: chapter.StoryID}), comment, chapter) + go func() { + story, err := stories.FindID(chapter.StoryID) + if err != nil { + log.Println("WARNING: Couldn't log comment change:", err) + return + } + + changes.Submit("Comment", "edit", token.UserID, true, changekeys.Many(comment, chapter, models.Story{ID: chapter.StoryID}), comment, chapter, story) + }() return comment, nil } @@ -142,5 +161,15 @@ func (r *mutationResolver) RemoveComment(ctx context.Context, input input.Commen return models.Comment{}, errors.New("Failed to remove comment: " + err.Error()) } + go func() { + story, err := stories.FindID(chapter.StoryID) + if err != nil { + log.Println("WARNING: Couldn't log comment change:", err) + return + } + + changes.Submit("Comment", "remove", token.UserID, true, changekeys.Many(comment, chapter, models.Story{ID: chapter.StoryID}), comment, chapter, story) + }() + return comment, nil } diff --git a/graph2/schema/types/Comment.gql b/graph2/schema/types/Comment.gql index 2200ba0..e322d18 100644 --- a/graph2/schema/types/Comment.gql +++ b/graph2/schema/types/Comment.gql @@ -8,6 +8,9 @@ type Comment { "subject" subject: String! + "The chapter ID the comment belongs to." + chapterId: String! + "The comment's author." author: String!