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.

26 lines
558 B

  1. package tags
  2. import (
  3. "sort"
  4. "strings"
  5. "git.aiterp.net/rpdata/api/models"
  6. "github.com/globalsign/mgo/bson"
  7. )
  8. // List lists all tags
  9. func List() ([]models.Tag, error) {
  10. tags := make([]models.Tag, 0, 64)
  11. err := storyCollection.Find(bson.M{"listed": true, "tags": bson.M{"$ne": nil}}).Distinct("tags", &tags)
  12. sort.Slice(tags, func(i, j int) bool {
  13. kindCmp := strings.Compare(string(tags[i].Kind), string(tags[j].Kind))
  14. if kindCmp != 0 {
  15. return kindCmp < 0
  16. }
  17. return strings.Compare(tags[i].Name, tags[j].Name) < 0
  18. })
  19. return tags, err
  20. }