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.

61 lines
1.7 KiB

  1. package models
  2. import "time"
  3. // Change represents a change in the rpdata history through the API.
  4. type Change struct {
  5. ID string `bson:"_id"`
  6. Model ChangeModel `bson:"model"`
  7. Op string `bson:"op"`
  8. Author string `bson:"author"`
  9. Listed bool `bson:"listed"`
  10. Keys []ChangeKey `bson:"keys"`
  11. Date time.Time `bson:"date"`
  12. Logs []Log `bson:"logs"`
  13. Characters []Character `bson:"characters"`
  14. Channels []Channel `bson:"channels"`
  15. Posts []Post `bson:"posts"`
  16. Stories []Story `bson:"stories"`
  17. Tags []Tag `bson:"tags"`
  18. Chapters []Chapter `bson:"chapters"`
  19. Comments []Comment `bson:"comments"`
  20. }
  21. // ChangeKey is a key for a change that can be used when subscribing to them.
  22. type ChangeKey struct {
  23. Model ChangeModel `bson:"model"`
  24. ID string `bson:"id"`
  25. }
  26. // Objects makes a combined, mixed array of all the models stored in this change.
  27. func (change *Change) Objects() []interface{} {
  28. data := make([]interface{}, 0, len(change.Logs)+len(change.Characters)+len(change.Channels)+len(change.Posts)+len(change.Stories)+len(change.Tags)+len(change.Chapters)+len(change.Comments))
  29. for _, log := range change.Logs {
  30. data = append(data, &log)
  31. }
  32. for _, channel := range change.Channels {
  33. data = append(data, &channel)
  34. }
  35. for _, character := range change.Characters {
  36. data = append(data, &character)
  37. }
  38. for _, post := range change.Posts {
  39. data = append(data, &post)
  40. }
  41. for _, story := range change.Stories {
  42. data = append(data, &story)
  43. }
  44. for _, tag := range change.Tags {
  45. data = append(data, &tag)
  46. }
  47. for _, chapter := range change.Chapters {
  48. data = append(data, &chapter)
  49. }
  50. for _, comment := range change.Comments {
  51. data = append(data, &comment)
  52. }
  53. return data
  54. }