2020-03-28 15:29:17 +01:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
|
|
|
)
|
|
|
|
|
2020-05-25 19:10:44 +02:00
|
|
|
// AccountSearch returns a list of accounts.
|
2020-06-01 09:45:24 +02:00
|
|
|
func AccountSearch(f form.AccountSearch) (result entity.Accounts, err error) {
|
2020-05-08 15:41:01 +02:00
|
|
|
s := Db().Where(&entity.Account{})
|
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")
|
|
|
|
|
|
|
|
if f.Count > 0 && f.Count <= 1000 {
|
|
|
|
s = s.Limit(f.Count).Offset(f.Offset)
|
|
|
|
} else {
|
|
|
|
s = s.Limit(1000).Offset(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.Find(&result).Error; err != nil {
|
2020-03-28 15:29:17 +01:00
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AccountByID finds an account by primary key.
|
2020-05-08 15:41:01 +02:00
|
|
|
func AccountByID(id uint) (result entity.Account, err error) {
|
|
|
|
if err := Db().Where("id = ?", id).First(&result).Error; err != nil {
|
2020-03-28 15:29:17 +01:00
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|