change returned product list struct

This commit is contained in:
Daniel Goc
2026-03-19 15:16:08 +01:00
parent b6bf6ed5c6
commit 1ea50af96a
5 changed files with 457 additions and 24 deletions

View File

@@ -1,6 +1,8 @@
package restricted
import (
"strconv"
"git.ma-al.com/goc_daniel/b2b/app/config"
"git.ma-al.com/goc_daniel/b2b/app/service/listProductsService"
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
@@ -50,7 +52,20 @@ func (h *ListProductsHandler) GetListing(c fiber.Ctx) error {
// "override_currency": c.Query("override_currency", ""),
// }
listing, err := h.listProductsService.GetListing(paging, filters)
id_shop_attribute := c.Query("shopID")
id_shop, err := strconv.Atoi(id_shop_attribute)
if err != nil {
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
id_lang, err := strconv.Atoi(c.Cookies("lang_id", "2"))
if err != nil {
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
listing, err := h.listProductsService.GetListing(uint(id_shop), uint(id_lang), paging, filters)
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))

View File

@@ -61,6 +61,13 @@ type Product struct {
State uint `gorm:"column:state" json:"state" form:"state"`
DeliveryDays uint `gorm:"column:delivery_days" json:"delivery_days" form:"delivery_days"`
}
type ProductInList struct {
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"`
Price float64 `gorm:"column:price;default:0.0" json:"price" form:"price"`
ActiveAsProduct uint `gorm:"column:active;default:0" json:"active_as_product" form:"active_as_product"`
ActiveInShop uint `gorm:"column:active;default:0" json:"active_in_shop" form:"active_in_shop"`
}
type ProductFilters struct {
Sort string `json:"sort,omitempty" query:"sort,omitempty" example:"price,asc;name,desc"` // sort rule

View File

@@ -17,8 +17,8 @@ func New() *ListProductsService {
}
}
func (s *ListProductsService) GetListing(p find.Paging, filters *filters.FiltersList) (find.Found[model.Product], error) {
var products find.Found[model.Product]
func (s *ListProductsService) GetListing(id_shop uint, id_lang uint, p find.Paging, filters *filters.FiltersList) (find.Found[model.ProductInList], error) {
var products find.Found[model.ProductInList]
// currencyIso := c.Cookies("currency_iso", "")
// countryIso := c.Cookies("country_iso", "")
@@ -30,7 +30,7 @@ func (s *ListProductsService) GetListing(p find.Paging, filters *filters.Filters
// countryIso = overrides["override_country"]
// }
products, err := s.listProductsRepo.GetListing(p, filters)
products, err := s.listProductsRepo.GetListing(id_shop, id_lang, p, filters)
if err != nil {
return products, err
}