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.
|
|
package logs
import ( "git.aiterp.net/rpdata/api/models" "github.com/globalsign/mgo/bson" )
// Filter for the List() function
type Filter struct { Search *string Characters *[]string Channels *[]string Events *[]string Open *bool Limit int }
// List lists all logs
func List(filter *Filter) ([]models.Log, error) { query := bson.M{} limit := 0
if filter != nil { // Run a text search
if filter.Search != nil { searchResults, err := search(*filter.Search) if err != nil { return nil, err }
// Posts always use shortId to refer to the log
query["shortId"] = bson.M{"$in": searchResults} }
// Find logs including any of the specified events and channels
if filter.Channels != nil { query["channel"] = bson.M{"$in": *filter.Channels} } if filter.Events != nil { query["event"] = bson.M{"$in": *filter.Events} }
// Find logs including all of the specified character IDs.
if filter.Characters != nil { query["characterIds"] = bson.M{"$all": *filter.Characters} }
// Limit to only open logs
if filter.Open != nil { query["open"] = *filter.Open }
// Set the limit from the filter
limit = filter.Limit }
return list(query, limit) }
func search(text string) ([]string, error) { query := bson.M{ "$text": bson.M{"$search": text}, "logId": bson.M{"$ne": nil}, }
ids := make([]string, 0, 64) err := postCollection.Find(query).Distinct("logId", &ids)
return ids, err }
|