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.

57 lines
1.6 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. }
  20. // ChangeKey is a key for a change that can be used when subscribing to them.
  21. type ChangeKey struct {
  22. Model ChangeModel `bson:"model"`
  23. ID string `bson:"id"`
  24. }
  25. // Objects makes a combined, mixed array of all the models stored in this change.
  26. func (change *Change) Objects() []interface{} {
  27. 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))
  28. for _, log := range change.Logs {
  29. data = append(data, log)
  30. }
  31. for _, channel := range change.Channels {
  32. data = append(data, channel)
  33. }
  34. for _, character := range change.Characters {
  35. data = append(data, character)
  36. }
  37. for _, post := range change.Posts {
  38. data = append(data, post)
  39. }
  40. for _, story := range change.Stories {
  41. data = append(data, story)
  42. }
  43. for _, tag := range change.Tags {
  44. data = append(data, tag)
  45. }
  46. for _, chapter := range change.Chapters {
  47. data = append(data, chapter)
  48. }
  49. return data
  50. }