Gisle Aune
6 years ago
4 changed files with 117 additions and 1 deletions
-
45graph2/queries/comment.go
-
3graph2/schema/root.gql
-
26graph2/schema/types/Comment.gql
-
44models/comments/edit.go
@ -0,0 +1,44 @@ |
|||||
|
package comments |
||||
|
|
||||
|
import ( |
||||
|
"time" |
||||
|
|
||||
|
"git.aiterp.net/rpdata/api/models" |
||||
|
"github.com/globalsign/mgo/bson" |
||||
|
) |
||||
|
|
||||
|
// Edit edits a comment.
|
||||
|
func Edit(comment models.Comment, source, characterName, characterID, subject *string, fictionalDate *time.Time) (models.Comment, error) { |
||||
|
changes := make(bson.M, 6) |
||||
|
|
||||
|
comment.EditedDate = time.Now() |
||||
|
changes["editedDate"] = comment.EditedDate |
||||
|
|
||||
|
if source != nil { |
||||
|
comment.Source = *source |
||||
|
changes["source"] = *source |
||||
|
} |
||||
|
if characterName != nil { |
||||
|
comment.CharacterName = *characterName |
||||
|
changes["characterName"] = *characterName |
||||
|
} |
||||
|
if characterID != nil { |
||||
|
comment.CharacterID = *characterID |
||||
|
changes["characterId"] = *characterID |
||||
|
} |
||||
|
if subject != nil { |
||||
|
comment.Subject = *subject |
||||
|
changes["subject"] = *subject |
||||
|
} |
||||
|
if fictionalDate != nil { |
||||
|
comment.FictionalDate = *fictionalDate |
||||
|
changes["fictionalDate"] = *fictionalDate |
||||
|
} |
||||
|
|
||||
|
err := collection.UpdateId(comment.ID, bson.M{"$set": changes}) |
||||
|
if err != nil { |
||||
|
return models.Comment{}, err |
||||
|
} |
||||
|
|
||||
|
return comment, nil |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue