endpoint returning tree of categories

This commit is contained in:
Daniel Goc
2026-03-20 12:38:41 +01:00
parent 0d29d8f6a2
commit b67c4e3aef
6 changed files with 144 additions and 30 deletions

View File

@@ -1,6 +1,12 @@
package categoriesRepo
import (
"git.ma-al.com/goc_daniel/b2b/app/db"
"git.ma-al.com/goc_daniel/b2b/app/model"
)
type UICategoriesRepo interface {
GetAllCategories(id_shop uint, id_lang uint) ([]model.ScannedCategory, error)
}
type CategoriesRepo struct{}
@@ -8,3 +14,28 @@ type CategoriesRepo struct{}
func New() UICategoriesRepo {
return &CategoriesRepo{}
}
func (repo *CategoriesRepo) GetAllCategories(id_shop uint, id_lang uint) ([]model.ScannedCategory, error) {
var allCategories []model.ScannedCategory
err := db.DB.Raw(`
SELECT
ps_category.id_category AS ID,
ps_category_lang.name AS name,
ps_category.active AS active,
ps_category_shop.position AS position,
ps_category.id_parent AS id_parent,
ps_category.is_root_category AS is_root_category
FROM ps_category
LEFT JOIN ps_category_lang
ON ps_category_lang.id_category = ps_category.id_category
AND ps_category_lang.id_shop = ?
AND ps_category_lang.id_lang = ?
LEFT JOIN ps_category_shop
ON ps_category_shop.id_category = ps_category.id_category
AND ps_category_shop.id_shop = ?`,
id_shop, id_lang, id_shop).
Scan(&allCategories).Error
return allCategories, err
}