chore: add favorite field to base product query
This commit is contained in:
@@ -18,7 +18,7 @@ type UIProductsRepo interface {
|
|||||||
// GetJSON(p_id_product, p_id_shop, p_id_lang, p_id_customer, b2b_id_country, p_quantity int) (*json.RawMessage, error)
|
// GetJSON(p_id_product, p_id_shop, p_id_lang, p_id_customer, b2b_id_country, p_quantity int) (*json.RawMessage, error)
|
||||||
Find(id_lang uint, userID uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.ProductInList], error)
|
Find(id_lang uint, userID uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.ProductInList], error)
|
||||||
GetProductVariants(langID uint, productID uint, shopID uint, customerID uint, countryID uint, quantity uint) ([]view.ProductAttribute, error)
|
GetProductVariants(langID uint, productID uint, shopID uint, customerID uint, countryID uint, quantity uint) ([]view.ProductAttribute, error)
|
||||||
GetBase(p_id_product, p_id_shop, p_id_lang uint) (view.Product, error)
|
GetBase(p_id_product, p_id_shop, p_id_lang, p_id_customer uint) (view.Product, error)
|
||||||
GetPrice(p_id_product uint, productAttributeID *uint, p_id_shop uint, p_id_customer uint, p_id_country uint, p_quantity uint) (view.Price, error)
|
GetPrice(p_id_product uint, productAttributeID *uint, p_id_shop uint, p_id_customer uint, p_id_country uint, p_quantity uint) (view.Price, error)
|
||||||
GetVariants(p_id_product, p_id_shop, p_id_lang, p_id_customer, p_id_country, p_quantity uint) ([]view.ProductAttribute, error)
|
GetVariants(p_id_product, p_id_shop, p_id_lang, p_id_customer, p_id_country, p_quantity uint) ([]view.ProductAttribute, error)
|
||||||
AddToFavorites(userID uint, productID uint) error
|
AddToFavorites(userID uint, productID uint) error
|
||||||
@@ -33,11 +33,11 @@ func New() UIProductsRepo {
|
|||||||
return &ProductsRepo{}
|
return &ProductsRepo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *ProductsRepo) GetBase(p_id_product, p_id_shop, p_id_lang uint) (view.Product, error) {
|
func (repo *ProductsRepo) GetBase(p_id_product, p_id_shop, p_id_lang, p_id_customer uint) (view.Product, error) {
|
||||||
var result view.Product
|
var result view.Product
|
||||||
|
|
||||||
err := db.DB.Raw(`CALL get_product_base(?,?,?)`,
|
err := db.DB.Raw(`CALL get_product_base(?,?,?,?)`,
|
||||||
p_id_product, p_id_shop, p_id_lang).
|
p_id_product, p_id_shop, p_id_lang, p_id_customer).
|
||||||
Scan(&result).Error
|
Scan(&result).Error
|
||||||
|
|
||||||
return result, err
|
return result, err
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func (s *ProductService) Get(
|
|||||||
p_id_product, p_id_lang, p_id_customer, b2b_id_country, p_quantity uint,
|
p_id_product, p_id_lang, p_id_customer, b2b_id_country, p_quantity uint,
|
||||||
) (*json.RawMessage, error) {
|
) (*json.RawMessage, error) {
|
||||||
|
|
||||||
product, err := s.productsRepo.GetBase(p_id_product, constdata.SHOP_ID, p_id_lang)
|
product, err := s.productsRepo.GetBase(p_id_product, constdata.SHOP_ID, p_id_lang, p_id_customer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -319,7 +319,8 @@ DROP PROCEDURE IF EXISTS get_product_base //
|
|||||||
CREATE PROCEDURE get_product_base(
|
CREATE PROCEDURE get_product_base(
|
||||||
IN p_id_product INT,
|
IN p_id_product INT,
|
||||||
IN p_id_shop INT,
|
IN p_id_shop INT,
|
||||||
IN p_id_lang INT
|
IN p_id_lang INT,
|
||||||
|
IN p_id_customer INT
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
SELECT
|
SELECT
|
||||||
@@ -376,14 +377,12 @@ BEGIN
|
|||||||
|
|
||||||
-- Relations
|
-- Relations
|
||||||
m.name AS manufacturer,
|
m.name AS manufacturer,
|
||||||
cl.name AS category
|
cl.name AS category,
|
||||||
|
|
||||||
-- This doesn't fit to base product, I'll add proper is_favorite to product later
|
EXISTS(
|
||||||
|
SELECT 1 FROM b2b_favorites f
|
||||||
-- EXISTS(
|
WHERE f.user_id = p_id_customer AND f.product_id = p_id_product
|
||||||
-- SELECT 1 FROM b2b_favorites f
|
) AS is_favorite
|
||||||
-- WHERE f.user_id = p_id_customer AND f.product_id = p_id_product
|
|
||||||
-- ) AS is_favorite
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user