change returned product list struct
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type UIListProductsRepo interface {
|
||||
GetListing(p find.Paging, filt *filters.FiltersList) (find.Found[model.Product], error)
|
||||
GetListing(id_shop uint, id_lang uint, p find.Paging, filt *filters.FiltersList) (find.Found[model.ProductInList], error)
|
||||
}
|
||||
|
||||
type ListProductsRepo struct{}
|
||||
@@ -17,12 +17,18 @@ func New() UIListProductsRepo {
|
||||
return &ListProductsRepo{}
|
||||
}
|
||||
|
||||
func (repo *ListProductsRepo) GetListing(p find.Paging, filt *filters.FiltersList) (find.Found[model.Product], error) {
|
||||
var listing []model.Product
|
||||
func (repo *ListProductsRepo) GetListing(id_shop uint, id_lang uint, p find.Paging, filt *filters.FiltersList) (find.Found[model.ProductInList], error) {
|
||||
var listing []model.ProductInList
|
||||
var total int64
|
||||
|
||||
// Apply filters here
|
||||
q := db.DB.Table("ps_product")
|
||||
q := db.DB.Table("ps_product").
|
||||
Select("ps_product.id_product AS id_product", "ps_product_lang.name AS name", "ps_product_shop.price AS price", "ps_product.active AS active_as_product", "ps_product_shop.active AS active_in_shop").
|
||||
Joins("LEFT JOIN ps_product_shop ON ps_product.id_product = ps_product_shop.id_product").
|
||||
Joins("LEFT JOIN ps_product_lang ON ps_product.id_product = ps_product_lang.id_product").
|
||||
Where("ps_product_shop.id_shop = ?", id_shop).
|
||||
Where("ps_product_lang.id_shop = ?", id_shop).
|
||||
Where("ps_product_lang.id_lang = ?", id_lang)
|
||||
|
||||
// var resultIDs []uint
|
||||
// q := db.DB.
|
||||
@@ -40,7 +46,7 @@ func (repo *ListProductsRepo) GetListing(p find.Paging, filt *filters.FiltersLis
|
||||
|
||||
err := q.Count(&total).Error
|
||||
if err != nil {
|
||||
return find.Found[model.Product]{}, err
|
||||
return find.Found[model.ProductInList]{}, err
|
||||
}
|
||||
|
||||
err = q.
|
||||
@@ -48,10 +54,10 @@ func (repo *ListProductsRepo) GetListing(p find.Paging, filt *filters.FiltersLis
|
||||
Offset(p.Offset()).
|
||||
Scan(&listing).Error
|
||||
if err != nil {
|
||||
return find.Found[model.Product]{}, err
|
||||
return find.Found[model.ProductInList]{}, err
|
||||
}
|
||||
|
||||
return find.Found[model.Product]{
|
||||
return find.Found[model.ProductInList]{
|
||||
Items: listing,
|
||||
Count: uint(total),
|
||||
}, nil
|
||||
|
||||
Reference in New Issue
Block a user