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.

42 lines
724 B

  1. package changes
  2. import (
  3. "time"
  4. "git.aiterp.net/rpdata/api/models"
  5. "github.com/globalsign/mgo/bson"
  6. )
  7. // Filter is a filter for changes.List.
  8. type Filter struct {
  9. Keys []models.ChangeKey
  10. EarliestDate *time.Time
  11. Limit *int
  12. }
  13. // List lists changes.
  14. func List(filter *Filter) ([]models.Change, error) {
  15. query := bson.M{}
  16. limit := 0
  17. if filter != nil {
  18. if filter.Limit != nil {
  19. limit = *filter.Limit
  20. }
  21. if filter.Keys != nil {
  22. query["keys"] = bson.M{"$in": filter.Keys}
  23. } else {
  24. query["listed"] = true
  25. }
  26. if filter.EarliestDate != nil {
  27. query["date"] = bson.M{"$gte": *filter.EarliestDate}
  28. }
  29. } else {
  30. query["listed"] = true
  31. limit = 256
  32. }
  33. return list(query, limit)
  34. }