package customerRepo import ( "git.ma-al.com/goc_daniel/b2b/app/db" "git.ma-al.com/goc_daniel/b2b/app/model" "git.ma-al.com/goc_daniel/b2b/app/utils/query/filters" "git.ma-al.com/goc_daniel/b2b/app/utils/query/find" ) type UICustomerRepo interface { Get(id uint) (*model.Customer, error) Find(langId uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.UserInList], error) } type CustomerRepo struct{} func New() UICustomerRepo { return &CustomerRepo{} } func (repo *CustomerRepo) Get(id uint) (*model.Customer, error) { var customer model.Customer err := db.DB. Preload("Role.Permissions"). First(&customer, id). Error return &customer, err } 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 // }