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.

36 lines
848 B

  1. package files
  2. import (
  3. "git.aiterp.net/rpdata/api/models"
  4. "github.com/globalsign/mgo/bson"
  5. )
  6. // Filter for files.List
  7. type Filter struct {
  8. Author *string
  9. Public *bool
  10. MimeType []string
  11. }
  12. // List lists files according to the standard lookup. By default it's just the author's own files,
  13. // but if `public` is true it will alos include files made public by other authors. If `mimeTypes` contains
  14. // any, it will limit the results to that. If `author` is empty, it will only list public files
  15. func List(filter *Filter) ([]models.File, error) {
  16. query := bson.M{}
  17. if filter != nil {
  18. if filter.Author != nil {
  19. query["author"] = *filter.Author
  20. }
  21. if filter.Public != nil {
  22. query["public"] = *filter.Public
  23. }
  24. if len(filter.MimeType) > 0 {
  25. query["mimeTypes"] = bson.M{"$in": filter.MimeType}
  26. }
  27. }
  28. return list(query)
  29. }