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.

41 lines
1.1 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 string `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. Posts []Post `bson:"posts"`
  15. }
  16. // ChangeKey is a key for a change that can be used when subscribing to them.
  17. type ChangeKey struct {
  18. Model string `bson:"model"`
  19. ID string `bson:"id"`
  20. }
  21. // Data makes a combined, mixed array of all the models stored in this change.
  22. func (change *Change) Data() []interface{} {
  23. data := make([]interface{}, 0, len(change.Logs)+len(change.Characters)+len(change.Posts))
  24. for _, log := range change.Logs {
  25. data = append(data, log)
  26. }
  27. for _, character := range change.Characters {
  28. data = append(data, character)
  29. }
  30. for _, post := range change.Posts {
  31. data = append(data, post)
  32. }
  33. return data
  34. }