GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1021 B

  1. package comments
  2. import (
  3. "time"
  4. "git.aiterp.net/rpdata/api/models"
  5. "github.com/globalsign/mgo/bson"
  6. )
  7. // Edit edits a comment.
  8. func Edit(comment models.Comment, source, characterName, characterID, subject *string, fictionalDate *time.Time) (models.Comment, error) {
  9. changes := make(bson.M, 6)
  10. comment.EditedDate = time.Now()
  11. changes["editedDate"] = comment.EditedDate
  12. if source != nil {
  13. comment.Source = *source
  14. changes["source"] = *source
  15. }
  16. if characterName != nil {
  17. comment.CharacterName = *characterName
  18. changes["characterName"] = *characterName
  19. }
  20. if characterID != nil {
  21. comment.CharacterID = *characterID
  22. changes["characterId"] = *characterID
  23. }
  24. if subject != nil {
  25. comment.Subject = *subject
  26. changes["subject"] = *subject
  27. }
  28. if fictionalDate != nil {
  29. comment.FictionalDate = *fictionalDate
  30. changes["fictionalDate"] = *fictionalDate
  31. }
  32. err := collection.UpdateId(comment.ID, bson.M{"$set": changes})
  33. if err != nil {
  34. return models.Comment{}, err
  35. }
  36. return comment, nil
  37. }