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
26 lines
558 B
package tags
|
|
|
|
import (
|
|
"sort"
|
|
"strings"
|
|
|
|
"git.aiterp.net/rpdata/api/models"
|
|
"github.com/globalsign/mgo/bson"
|
|
)
|
|
|
|
// List lists all tags
|
|
func List() ([]models.Tag, error) {
|
|
tags := make([]models.Tag, 0, 64)
|
|
err := storyCollection.Find(bson.M{"listed": true, "tags": bson.M{"$ne": nil}}).Distinct("tags", &tags)
|
|
|
|
sort.Slice(tags, func(i, j int) bool {
|
|
kindCmp := strings.Compare(string(tags[i].Kind), string(tags[j].Kind))
|
|
if kindCmp != 0 {
|
|
return kindCmp < 0
|
|
}
|
|
|
|
return strings.Compare(tags[i].Name, tags[j].Name) < 0
|
|
})
|
|
|
|
return tags, err
|
|
}
|