/
githubmirror
/
photoprism
Обзор
Документация
Войти
/
githubmirror
/
photoprism
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
internal/entity/query/clients.go
42 строки
942 B
Michael Mayer
Backend: Move customize, pwa, ttl, query, classify and nsfw packages
02 июл 2024, 08:36
02 июл 2024, 08:36
7f60af3
Код
Авторство
О чём код?
package query import ( "strings" "github.com/photoprism/photoprism/internal/entity" "github.com/photoprism/photoprism/pkg/rnd" ) // Clients finds clients and returns them. func Clients(limit, offset int, sortOrder, search string) (result entity.Clients, err error) { result = entity.Clients{} stmt := Db() search = strings.TrimSpace(search) if search == "all" { // Don't filter. } else if rnd.IsUID(search, entity.ClientUID) { stmt = stmt.Where("client_uid = ?", search) } else if rnd.IsUID(search, entity.UserUID) { stmt = stmt.Where("user_uid = ?", search) } else if search != "" { stmt = stmt.Where("client_name LIKE ? OR user_name LIKE ?", search+"%", search+"%") } if sortOrder == "" { sortOrder = "created_at DESC, client_uid DESC" } if limit > 0 { stmt = stmt.Limit(limit) if offset > 0 { stmt = stmt.Offset(offset) } } err = stmt.Order(sortOrder).Find(&result).Error return result, err }