40 lines
947 B
Go
40 lines
947 B
Go
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.Customer], 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.Customer], error) {
|
|
found, err := find.Paginate[model.Customer](langId, p, db.DB.
|
|
Model(&model.Customer{}).
|
|
Scopes(filt.All()...),
|
|
)
|
|
|
|
return &found, err
|
|
}
|