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
46 lines
1.0 KiB
package channels
|
|
|
|
import (
|
|
"git.aiterp.net/rpdata/api/models"
|
|
"github.com/globalsign/mgo/bson"
|
|
)
|
|
|
|
// Filter for searching
|
|
type Filter struct {
|
|
Logged *bool `json:"logged"`
|
|
EventName string `json:"eventName"`
|
|
LocationName string `json:"locationName"`
|
|
}
|
|
|
|
// List finds channels, if logged is true it will be limited to logged
|
|
// channels
|
|
func List(filter *Filter) ([]models.Channel, error) {
|
|
query := bson.M{}
|
|
|
|
if filter != nil {
|
|
if filter.Logged != nil {
|
|
query["logged"] = *filter.Logged
|
|
}
|
|
if filter.EventName != "" {
|
|
query["eventName"] = filter.EventName
|
|
}
|
|
if filter.LocationName != "" {
|
|
query["locationName"] = filter.LocationName
|
|
}
|
|
}
|
|
|
|
channels := make([]models.Channel, 0, 128)
|
|
err := collection.Find(query).Sort("_id").All(&channels)
|
|
|
|
return channels, err
|
|
}
|
|
|
|
// ListNames finds channels by the names provided
|
|
func ListNames(names ...string) ([]models.Channel, error) {
|
|
query := bson.M{"_id": bson.M{"$in": names}}
|
|
|
|
channels := make([]models.Channel, 0, 32)
|
|
err := collection.Find(query).All(&channels)
|
|
|
|
return channels, err
|
|
}
|