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.

35 lines
791 B

  1. package comments
  2. import (
  3. "time"
  4. "git.aiterp.net/rpdata/api/models"
  5. )
  6. // Add adds a comment.
  7. func Add(chapter models.Chapter, subject, author, source, characterName string, character *models.Character, createdDate time.Time, fictionalDate time.Time) (models.Comment, error) {
  8. characterID := ""
  9. if character != nil {
  10. characterID = character.ID
  11. }
  12. comment := models.Comment{
  13. ID: makeCommentID(),
  14. ChapterID: chapter.ID,
  15. Subject: subject,
  16. Author: author,
  17. CharacterName: characterName,
  18. CharacterID: characterID,
  19. FictionalDate: fictionalDate,
  20. CreatedDate: createdDate,
  21. EditedDate: createdDate,
  22. Source: source,
  23. }
  24. err := collection.Insert(comment)
  25. if err != nil {
  26. return models.Comment{}, err
  27. }
  28. return comment, nil
  29. }