Changed files graphql query to use a filter argument to look more like other queries.

This commit is contained in:
2018-07-15 15:34:58 +02:00
parent 51489ed901
commit 26d7e36631
5 changed files with 31 additions and 19 deletions
+8 -7
View File
@@ -168,21 +168,22 @@ func FindName(kind string, name string, author string) (File, error) {
// List lists files according to the standard lookup. By default it's just the author's own files,
// but if `public` is true it will alos include files made public by other authors. If `mimeTypes` contains
// any, it will limit the results to that. If `author` is empty, it will only list public files
func List(author string, public bool, mimeTypes []string) ([]File, error) {
func List(author string, public *bool, mimeTypes []string) ([]File, error) {
query := bson.M{}
if author != "" {
if public {
query["$or"] = []bson.M{
bson.M{"author": author},
bson.M{"public": true},
if public != nil {
if *public == false {
query["author"] = author
}
query["public"] = *public
} else {
query["author"] = author
}
} else {
if !public {
return nil, errors.New("No author specified, and public is unset")
if public != nil && *public == false {
return nil, errors.New("You cannot")
}
query["public"] = true