2020-01-05 14:18:40 +01:00
|
|
|
package query
|
2019-12-28 20:24:20 +01:00
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
import "github.com/photoprism/photoprism/pkg/txt"
|
2019-12-28 20:24:20 +01:00
|
|
|
|
|
|
|
type CategoryLabel struct {
|
2019-12-28 20:39:51 +01:00
|
|
|
Name string
|
2019-12-28 20:24:20 +01:00
|
|
|
Title string
|
|
|
|
}
|
|
|
|
|
2020-05-08 15:41:01 +02:00
|
|
|
func CategoryLabels(limit, offset int) (results []CategoryLabel) {
|
|
|
|
s := Db().NewScope(nil).DB()
|
2019-12-28 20:24:20 +01:00
|
|
|
|
2020-03-28 17:17:41 +01:00
|
|
|
s = s.Table("categories").
|
2019-12-28 20:24:20 +01:00
|
|
|
Select("label_name AS name").
|
|
|
|
Joins("JOIN labels l ON categories.category_id = l.id").
|
|
|
|
Group("label_name").
|
|
|
|
Limit(limit).Offset(offset)
|
|
|
|
|
2020-03-28 17:17:41 +01:00
|
|
|
if err := s.Scan(&results).Error; err != nil {
|
2019-12-28 20:24:20 +01:00
|
|
|
log.Errorf("categories: %s", err.Error())
|
|
|
|
return results
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, l := range results {
|
2022-04-15 09:42:07 +02:00
|
|
|
results[i].Title = txt.Title(l.Name)
|
2019-12-28 20:24:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return results
|
|
|
|
}
|