added ImageID and LinkRewrite

This commit is contained in:
Daniel Goc
2026-03-20 09:31:08 +01:00
parent 1ea50af96a
commit 884e15bb8a
6 changed files with 129 additions and 12 deletions

View File

@@ -0,0 +1,39 @@
package restricted
import (
"git.ma-al.com/goc_daniel/b2b/app/service/menuService"
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
"github.com/gofiber/fiber/v3"
)
type MenuHandler struct {
menuService *menuService.MenuService
}
func NewMenuHandler() *MenuHandler {
menuService := menuService.New()
return &MenuHandler{
menuService: menuService,
}
}
func MenuHandlerRoutes(r fiber.Router) fiber.Router {
handler := NewMenuHandler()
r.Get("/get-menu", handler.GetMenu)
return r
}
func (h *MenuHandler) GetMenu(c fiber.Ctx) error {
menu, err := h.menuService.GetMenu()
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
}
return c.JSON(response.Make(&menu, 0, i18n.T_(c, response.Message_OK)))
}

View File

@@ -102,6 +102,10 @@ func (s *Server) Setup() error {
langsAndCountries := s.restricted.Group("/langs-and-countries") langsAndCountries := s.restricted.Group("/langs-and-countries")
restricted.LangsAndCountriesHandlerRoutes(langsAndCountries) restricted.LangsAndCountriesHandlerRoutes(langsAndCountries)
// menu (restricted)
menu := s.restricted.Group("/menu")
restricted.MenuHandlerRoutes(menu)
// // Restricted routes example // // Restricted routes example
// restricted := s.api.Group("/restricted") // restricted := s.api.Group("/restricted")
// restricted.Use(middleware.AuthMiddleware()) // restricted.Use(middleware.AuthMiddleware())

View File

@@ -62,11 +62,11 @@ type Product struct {
DeliveryDays uint `gorm:"column:delivery_days" json:"delivery_days" form:"delivery_days"` DeliveryDays uint `gorm:"column:delivery_days" json:"delivery_days" form:"delivery_days"`
} }
type ProductInList struct { type ProductInList struct {
ID uint `gorm:"column:id_product;primaryKey" json:"product_id" form:"product_id"` ID uint `gorm:"column:id_product;primaryKey" json:"product_id" form:"product_id"`
Name string `gorm:"column:name;default:'no name'" json:"name" form:"name"` Name string `gorm:"column:name" json:"name" form:"name"`
Price float64 `gorm:"column:price;default:0.0" json:"price" form:"price"` ImageID uint `gorm:"column:id_image"`
ActiveAsProduct uint `gorm:"column:active;default:0" json:"active_as_product" form:"active_as_product"` LinkRewrite string `gorm:"column:link_rewrite"`
ActiveInShop uint `gorm:"column:active;default:0" json:"active_in_shop" form:"active_in_shop"` Active uint `gorm:"column:active" json:"active" form:"active"`
} }
type ProductFilters struct { type ProductFilters struct {

View File

@@ -0,0 +1,46 @@
package menuService
import "git.ma-al.com/goc_daniel/b2b/repository/categoriesRepo"
type MenuService struct {
categoriesRepo categoriesRepo.UICategoriesRepo
}
func New() *MenuService {
return &MenuService{
categoriesRepo: categoriesRepo.New(),
}
}
func (s *MenuService) GetMenu() (string, error) {
// var menu_json string
// products, err := s.listProductsRepo.GetListing(id_shop, id_lang, p, filters)
// if err != nil {
// return products, err
// }
// var loopErr error
// parallel.ForEach(products.Items, func(t model.Product, i int) {
// // products.Items[i].PriceTaxed *= currRate.Rate.InexactFloat64()
// // products.Items[i].PriceTaxed = tiny_util.RoundUpMonetary(products.Items[i].PriceTaxed)
// if products.Items[i].Name.IsNull() {
// translation, err := s.listProductsRepo.GetTranslation(ctx, products.Items[i].ID, defaults.DefaultLanguageID)
// if err != nil {
// loopErr = err
// return
// }
// products.Items[i].Name = nullable.FromPrimitiveString(translation.Name)
// products.Items[i].DescriptionShort = nullable.FromPrimitiveString(translation.DescriptionShort)
// products.Items[i].LinkRewrite = nullable.FromPrimitiveString(translation.LinkRewrite)
// }
// })
// if loopErr != nil {
// return products, errs.Handled(span, loopErr, errs.InternalError, errs.ERR_TODO)
// }
// return products, nil
return "", nil
}

View File

@@ -0,0 +1,10 @@
package categoriesRepo
type UICategoriesRepo interface {
}
type CategoriesRepo struct{}
func New() UICategoriesRepo {
return &CategoriesRepo{}
}

View File

@@ -22,13 +22,31 @@ func (repo *ListProductsRepo) GetListing(id_shop uint, id_lang uint, p find.Pagi
var total int64 var total int64
// Apply filters here // Apply filters here
q := db.DB.Table("ps_product"). q := db.DB.Raw(`
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"). SELECT
Joins("LEFT JOIN ps_product_shop ON ps_product.id_product = ps_product_shop.id_product"). ps_product.id_product AS ID,
Joins("LEFT JOIN ps_product_lang ON ps_product.id_product = ps_product_lang.id_product"). ps_product_lang.name AS Name,
Where("ps_product_shop.id_shop = ?", id_shop). ps_product.active AS Active,
Where("ps_product_lang.id_shop = ?", id_shop). ps_product_lang.link_rewrite AS LinkRewrite,
Where("ps_product_lang.id_lang = ?", id_lang) COALESCE (
ps_image_shop.id_image, any_image.id_image
) AS ImageID
FROM ps_product
LEFT JOIN ps_product_lang
ON ps_product_lang.id_product = ps_product.id_product
AND ps_product_lang.id_shop = ?
AND ps_product_lang.id_lang = ?
LEFT JOIN ps_image_shop
ON ps_image_shop.id_product = ps_product.id_product
AND ps_image_shop.id_shop = ?
AND ps_image_shop.cover = 1
LEFT JOIN (
SELECT id_product, MIN(id_image) AS id_image
FROM ps_image
GROUP BY id_product
) any_image
ON ps_product.id_product = any_image.id_product`,
id_shop, id_lang, id_shop)
// var resultIDs []uint // var resultIDs []uint
// q := db.DB. // q := db.DB.