new endpoint to return product list
This commit is contained in:
58
repository/listProductsRepo/listProductsRepo.go
Normal file
58
repository/listProductsRepo/listProductsRepo.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package listProductsRepo
|
||||
|
||||
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 UIListProductsRepo interface {
|
||||
GetListing(p find.Paging, filt *filters.FiltersList) (find.Found[model.Product], error)
|
||||
}
|
||||
|
||||
type ListProductsRepo struct{}
|
||||
|
||||
func New() UIListProductsRepo {
|
||||
return &ListProductsRepo{}
|
||||
}
|
||||
|
||||
func (repo *ListProductsRepo) GetListing(p find.Paging, filt *filters.FiltersList) (find.Found[model.Product], error) {
|
||||
var listing []model.Product
|
||||
var total int64
|
||||
|
||||
// Apply filters here
|
||||
q := db.DB.Table("ps_product")
|
||||
|
||||
// var resultIDs []uint
|
||||
// q := db.DB.
|
||||
// // SQL_CALC_FOUND_ROWS is a neat trick which works on MariaDB and
|
||||
// // MySQL. It works when followed by `SELECT FOUND_ROWS();`. To learn
|
||||
// // more see: https://mariarawmodel.com/kb/en/found_rows/
|
||||
// // WARN: This might not work on different SQL databases
|
||||
// Select("DISTINCT SQL_CALC_FOUND_ROWS id").
|
||||
// // Debug().
|
||||
// Scopes(view.FromDBViewForDisplay(langID, countryIso)).
|
||||
// Scopes(scopesForFiltersOnDisplay(db.DB, langID, countryIso, filt)).
|
||||
// Scopes(filt.OfCategory(filters.ORDER_FILTER)...).
|
||||
// Limit(p.Limit()).
|
||||
// Offset(p.Offset())
|
||||
|
||||
err := q.Count(&total).Error
|
||||
if err != nil {
|
||||
return find.Found[model.Product]{}, err
|
||||
}
|
||||
|
||||
err = q.
|
||||
Limit(p.Limit()).
|
||||
Offset(p.Offset()).
|
||||
Scan(&listing).Error
|
||||
if err != nil {
|
||||
return find.Found[model.Product]{}, err
|
||||
}
|
||||
|
||||
return find.Found[model.Product]{
|
||||
Items: listing,
|
||||
Count: uint(total),
|
||||
}, nil
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package ProductDescriptionRepo
|
||||
package productDescriptionRepo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
Reference in New Issue
Block a user