2021-09-18 15:32:39 +02:00
|
|
|
package search
|
2020-03-28 15:29:17 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
|
|
|
)
|
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
// Accounts returns a list of accounts.
|
2022-10-15 21:54:11 +02:00
|
|
|
func Accounts(f form.SearchServices) (result entity.Services, err error) {
|
|
|
|
s := Db().Where(&entity.Service{})
|
2020-03-31 17:26:25 +02:00
|
|
|
|
|
|
|
if f.Share {
|
|
|
|
s = s.Where("acc_share = 1")
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Sync {
|
|
|
|
s = s.Where("acc_sync = 1")
|
|
|
|
}
|
|
|
|
|
2020-04-04 17:19:34 +02:00
|
|
|
if f.Status != "" {
|
|
|
|
s = s.Where("sync_status = ?", f.Status)
|
|
|
|
}
|
|
|
|
|
2020-03-31 17:26:25 +02:00
|
|
|
s = s.Order("acc_name ASC")
|
|
|
|
|
2020-07-01 09:49:03 +02:00
|
|
|
if f.Count > 0 && f.Count <= MaxResults {
|
2020-03-31 17:26:25 +02:00
|
|
|
s = s.Limit(f.Count).Offset(f.Offset)
|
|
|
|
} else {
|
2020-07-01 09:49:03 +02:00
|
|
|
s = s.Limit(MaxResults).Offset(f.Offset)
|
2020-03-31 17:26:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.Find(&result).Error; err != nil {
|
2020-03-28 15:29:17 +01:00
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|