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.

46 lines
1.0 KiB

  1. package channels
  2. import (
  3. "git.aiterp.net/rpdata/api/models"
  4. "github.com/globalsign/mgo/bson"
  5. )
  6. // Filter for searching
  7. type Filter struct {
  8. Logged *bool `json:"logged"`
  9. EventName string `json:"eventName"`
  10. LocationName string `json:"locationName"`
  11. }
  12. // List finds channels, if logged is true it will be limited to logged
  13. // channels
  14. func List(filter *Filter) ([]models.Channel, error) {
  15. query := bson.M{}
  16. if filter != nil {
  17. if filter.Logged != nil {
  18. query["logged"] = *filter.Logged
  19. }
  20. if filter.EventName != "" {
  21. query["eventName"] = filter.EventName
  22. }
  23. if filter.LocationName != "" {
  24. query["locationName"] = filter.LocationName
  25. }
  26. }
  27. channels := make([]models.Channel, 0, 128)
  28. err := collection.Find(query).Sort("_id").All(&channels)
  29. return channels, err
  30. }
  31. // ListNames finds channels by the names provided
  32. func ListNames(names ...string) ([]models.Channel, error) {
  33. query := bson.M{"_id": bson.M{"$in": names}}
  34. channels := make([]models.Channel, 0, 32)
  35. err := collection.Find(query).All(&channels)
  36. return channels, err
  37. }