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.

59 lines
1.6 KiB

  1. package models
  2. import "time"
  3. // A Chapter is a part of a story.
  4. type Chapter struct {
  5. ID string `bson:"_id"`
  6. StoryID string `bson:"storyId"`
  7. Title string `bson:"title"`
  8. Author string `bson:"author"`
  9. Source string `bson:"source"`
  10. CreatedDate time.Time `bson:"createdDate"`
  11. FictionalDate time.Time `bson:"fictionalDate,omitempty"`
  12. EditedDate time.Time `bson:"editedDate"`
  13. CommentMode ChapterCommentMode `bson:"commentMode"`
  14. CommentsLocked bool `bson:"commentsLocked"`
  15. }
  16. func (chapter *Chapter) ApplyUpdate(update ChapterUpdate) {
  17. if update.Title != nil {
  18. chapter.Title = *update.Title
  19. }
  20. if update.Source != nil {
  21. chapter.Source = *update.Source
  22. }
  23. if update.FictionalDate != nil {
  24. chapter.FictionalDate = update.FictionalDate.UTC()
  25. }
  26. if update.CommentMode != nil {
  27. chapter.CommentMode = *update.CommentMode
  28. }
  29. if update.CommentsLocked != nil {
  30. chapter.CommentsLocked = *update.CommentsLocked
  31. }
  32. }
  33. // CanComment returns true if the chapter can be commented to.
  34. func (chapter *Chapter) CanComment() bool {
  35. return !chapter.CommentsLocked && chapter.CommentMode.IsEnabled()
  36. }
  37. // IsChangeObject is an interface implementation to identify it as a valid
  38. // ChangeObject in GQL.
  39. func (*Chapter) IsChangeObject() {
  40. panic("this method is a dummy, and so is its caller")
  41. }
  42. type ChapterFilter struct {
  43. StoryID *string
  44. Limit int
  45. }
  46. type ChapterUpdate struct {
  47. Title *string
  48. Source *string
  49. FictionalDate *time.Time
  50. CommentMode *ChapterCommentMode
  51. CommentsLocked *bool
  52. }