refactor: move lists to their representative repos

This commit is contained in:
2026-04-07 10:32:30 +02:00
parent 813d1f4879
commit 9187297367
13 changed files with 167 additions and 314 deletions

View File

@@ -9,7 +9,7 @@ import (
type UICustomerRepo interface {
Get(id uint) (*model.Customer, error)
Find(langId uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.Customer], error)
Find(langId uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.UserInList], error)
}
type CustomerRepo struct{}
@@ -29,11 +29,57 @@ func (repo *CustomerRepo) Get(id uint) (*model.Customer, error) {
return &customer, err
}
func (repo *CustomerRepo) Find(langId uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.Customer], error) {
found, err := find.Paginate[model.Customer](langId, p, db.DB.
Model(&model.Customer{}).
func (repo *CustomerRepo) Find(langId uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.UserInList], error) {
found, err := find.Paginate[model.UserInList](langId, p, db.DB.
Table("b2b_customers AS users").
Select(`
users.id AS id,
users.email AS email,
users.first_name AS first_name,
users.last_name AS last_name
`).
Scopes(filt.All()...),
)
return &found, err
}
// func (repo *ListRepo) ListUsers(id_lang uint, p find.Paging, filt *filters.FiltersList) (find.Found[model.UserInList], error) {
// var list []model.UserInList
// var total int64
// query := db.Get().
// Table("b2b_customers AS users").
// Select(`
// users.id AS id,
// users.email AS email,
// users.first_name AS first_name,
// users.last_name AS last_name,
// users.role AS role
// `)
// // Apply all filters
// if filt != nil {
// filt.ApplyAll(query)
// }
// // run counter first as query is without limit and offset
// err := query.Count(&total).Error
// if err != nil {
// return find.Found[model.UserInList]{}, err
// }
// err = query.
// Order("users.id DESC").
// Limit(p.Limit()).
// Offset(p.Offset()).
// Find(&list).Error
// if err != nil {
// return find.Found[model.UserInList]{}, err
// }
// return find.Found[model.UserInList]{
// Items: list,
// Count: uint(total),
// }, nil
// }