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.

74 lines
2.2 KiB

  1. package models
  2. import "time"
  3. // A Story is user content that does not have a wiki-suitable format. Documents, new stories, short stories, and so on.
  4. // The story model is a container for multiple chapters this time, in contrast to the previous version.
  5. type Story struct {
  6. ID string `bson:"_id"`
  7. Author string `bson:"author"`
  8. Name string `bson:"name"`
  9. Category StoryCategory `bson:"category"`
  10. Open bool `bson:"open"`
  11. Listed bool `bson:"listed"`
  12. Tags []Tag `bson:"tags"`
  13. CreatedDate time.Time `bson:"createdDate"`
  14. FictionalDate time.Time `bson:"fictionalDate,omitempty"`
  15. UpdatedDate time.Time `bson:"updatedDate"`
  16. SortByFictionalDate bool `bson:"sortByFictionalDate"`
  17. }
  18. func (story *Story) ApplyUpdate(update StoryUpdate) {
  19. if update.Name != nil {
  20. story.Name = *update.Name
  21. }
  22. if update.Category != nil {
  23. story.Category = *update.Category
  24. }
  25. if update.Author != nil {
  26. story.Author = *update.Author
  27. }
  28. if update.Open != nil {
  29. story.Open = *update.Open
  30. }
  31. if update.Listed != nil {
  32. story.Listed = *update.Listed
  33. }
  34. if update.SortByFictionalDate != nil {
  35. story.SortByFictionalDate = *update.SortByFictionalDate
  36. }
  37. if update.FictionalDate != nil {
  38. story.FictionalDate = *update.FictionalDate
  39. }
  40. if update.UpdatedDate != nil {
  41. story.UpdatedDate = *update.UpdatedDate
  42. }
  43. }
  44. // IsChangeObject is an interface implementation to identify it as a valid
  45. // ChangeObject in GQL.
  46. func (_ *Story) IsChangeObject() {
  47. panic("this method is a dummy, and so is its caller")
  48. }
  49. type StoryFilter struct {
  50. Author *string
  51. Tags []Tag
  52. EarliestFictionalDate time.Time
  53. LatestFictionalDate time.Time
  54. Category *StoryCategory
  55. Open *bool
  56. Unlisted *bool
  57. Limit int
  58. }
  59. type StoryUpdate struct {
  60. Name *string
  61. Category *StoryCategory
  62. Author *string
  63. Open *bool
  64. Listed *bool
  65. FictionalDate *time.Time
  66. UpdatedDate *time.Time
  67. SortByFictionalDate *bool
  68. }