Changed characters graphql query to use the filter format, changed description for files query to match the others'
the build was successful

This commit is contained in:
2018-07-15 17:55:21 +02:00
parent 18e77b8205
commit ba1c1e0a4b
4 changed files with 85 additions and 33 deletions
+29
View File
@@ -154,6 +154,29 @@ func ListIDs(ids ...string) ([]Character, error) {
return list(bson.M{"_id": bson.M{"$in": ids}})
}
// ListFilter lists all logs matching the filters.
func ListFilter(ids []string, nicks []string, names []string, author *string, search *string) ([]Character, error) {
query := bson.M{}
if len(ids) > 0 {
query["_id"] = bson.M{"$in": ids}
}
if len(nicks) > 0 {
query["nicks"] = bson.M{"$in": nicks}
}
if len(names) > 0 {
query["name"] = bson.M{"$in": names}
}
if author != nil {
query["author"] = *author
}
if search != nil {
query["$text"] = bson.M{"$search": *search}
}
return list(query)
}
// New creates a Character and pushes it to the database. It does some validation
// on nick, name, shortName and author. Leave the shortname blank to have it be the
// first name.
@@ -227,5 +250,11 @@ func init() {
if err != nil {
log.Fatalln("init common.characters:", err)
}
err = collection.EnsureIndex(mgo.Index{
Key: []string{"$text:description"},
})
if err != nil {
log.Fatalln("init common.characters:", err)
}
})
}