feat: setup editable product struct
This commit is contained in:
@@ -22,7 +22,6 @@ type ProductsHandler struct {
|
|||||||
config *config.Config
|
config *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewListProductsHandler creates a new ListProductsHandler instance
|
|
||||||
func NewProductsHandler() *ProductsHandler {
|
func NewProductsHandler() *ProductsHandler {
|
||||||
productService := productService.New()
|
productService := productService.New()
|
||||||
return &ProductsHandler{
|
return &ProductsHandler{
|
||||||
|
|||||||
85
app/delivery/web/api/restricted/productEditing.go
Normal file
85
app/delivery/web/api/restricted/productEditing.go
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
package restricted
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/service/productEditingService"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
|
||||||
|
"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 ProductEditingHandler struct {
|
||||||
|
productEditingService *productEditingService.ProductEditingService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewProductEditingHandler() *ProductEditingHandler {
|
||||||
|
productEditingService := productEditingService.New()
|
||||||
|
return &ProductEditingHandler{
|
||||||
|
productEditingService: productEditingService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProductEditingHandlerRoutes(r fiber.Router) fiber.Router {
|
||||||
|
handler := NewProductEditingHandler()
|
||||||
|
|
||||||
|
r.Get("/:id", handler.GetProduct)
|
||||||
|
r.Post("/:id", handler.SaveProduct)
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ProductEditingHandler) GetProduct(c fiber.Ctx) error {
|
||||||
|
idStr := c.Params("id")
|
||||||
|
|
||||||
|
p_id_product, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
product, err := h.productEditingService.GetProduct(uint(p_id_product))
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("failed to load editable product",
|
||||||
|
"product_id", p_id_product,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(response.Make(product, 1, i18n.T_(c, response.Message_OK)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ProductEditingHandler) SaveProduct(c fiber.Ctx) error {
|
||||||
|
idStr := c.Params("id")
|
||||||
|
|
||||||
|
p_id_product, err := strconv.Atoi(idStr)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
var product model.ProductEditing
|
||||||
|
err = c.Bind().Body(&product)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrJSONBody)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrJSONBody)))
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.productEditingService.SaveProduct(uint(p_id_product), &product)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("failed to save editable product",
|
||||||
|
"product_id", p_id_product,
|
||||||
|
"error", err.Error(),
|
||||||
|
)
|
||||||
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
|
||||||
|
}
|
||||||
@@ -116,6 +116,10 @@ func (s *Server) Setup() error {
|
|||||||
product := s.restricted.Group("/product")
|
product := s.restricted.Group("/product")
|
||||||
restricted.ProductsHandlerRoutes(product)
|
restricted.ProductsHandlerRoutes(product)
|
||||||
|
|
||||||
|
// editing products
|
||||||
|
productEditing := s.restricted.Group("/product-editing")
|
||||||
|
restricted.ProductEditingHandlerRoutes(productEditing)
|
||||||
|
|
||||||
// locale selector (restricted)
|
// locale selector (restricted)
|
||||||
// this is basically for changing user's selected language and country
|
// this is basically for changing user's selected language and country
|
||||||
localeSelector := s.restricted.Group("/langs-and-countries")
|
localeSelector := s.restricted.Group("/langs-and-countries")
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
import "git.ma-al.com/goc_daniel/b2b/app/model/dbmodel"
|
||||||
|
|
||||||
type ProductInList struct {
|
type ProductInList struct {
|
||||||
ProductID uint `gorm:"column:product_id" json:"product_id" form:"product_id"`
|
ProductID uint `gorm:"column:product_id" json:"product_id" form:"product_id"`
|
||||||
Name string `gorm:"column:name" json:"name" form:"name"`
|
Name string `gorm:"column:name" json:"name" form:"name"`
|
||||||
@@ -38,3 +40,28 @@ type B2bFavorite struct {
|
|||||||
func (*B2bFavorite) TableName() string {
|
func (*B2bFavorite) TableName() string {
|
||||||
return "b2b_favorites"
|
return "b2b_favorites"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// contains everything that is editable in product (and possibly more)
|
||||||
|
type ProductEditing struct {
|
||||||
|
Product dbmodel.PsProduct `json:"product,omitempty"`
|
||||||
|
ProductShop dbmodel.PsProductShop `json:"product_shop,omitempty"`
|
||||||
|
ProductLang []dbmodel.PsProductLang `json:"product_lang,omitempty"`
|
||||||
|
CategoryProduct []dbmodel.PsCategoryProduct `json:"category_product"`
|
||||||
|
ProductTag []dbmodel.PsTag `json:"tag"`
|
||||||
|
Feature []ProductFeature `json:"features"`
|
||||||
|
Attachments []dbmodel.PsProductAttachment `json:"product_attachment"`
|
||||||
|
Carrier []dbmodel.PsProductCarrier `json:"product_carrier"`
|
||||||
|
Accessory []dbmodel.PsAccessory `json:"accessory"`
|
||||||
|
SpecificPrice []dbmodel.PsSpecificPrice `json:"specific_price"`
|
||||||
|
SpecificPricePriority []dbmodel.PsSpecificPricePriority `json:"specific_price_priority"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProductFeature struct {
|
||||||
|
FeatureValue dbmodel.PsFeatureValue `json:"featue_value"`
|
||||||
|
FeatureValueLang []dbmodel.PsFeatureValueLang `json:"featue_value_lang"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProductCustomizationField struct {
|
||||||
|
CustomizationField dbmodel.PsCustomizationField `json:"customization_field"`
|
||||||
|
CustomizationFieldLang dbmodel.PsCustomizationFieldLang `json:"customization_field_lang"`
|
||||||
|
}
|
||||||
|
|||||||
10
app/repos/productEditingRepo/productEditingRepo.go
Normal file
10
app/repos/productEditingRepo/productEditingRepo.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package productEditingRepo
|
||||||
|
|
||||||
|
type UIProductEditingRepo interface {
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProductEditingRepo struct{}
|
||||||
|
|
||||||
|
func New() UIProductEditingRepo {
|
||||||
|
return &ProductEditingRepo{}
|
||||||
|
}
|
||||||
26
app/service/productEditingService/productEditingService.go
Normal file
26
app/service/productEditingService/productEditingService.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package productEditingService
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/repos/productEditingRepo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ProductEditingService struct {
|
||||||
|
repo productEditingRepo.UIProductEditingRepo
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() *ProductEditingService {
|
||||||
|
return &ProductEditingService{
|
||||||
|
repo: productEditingRepo.New(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ProductEditingService) GetProduct(id uint) (*model.ProductEditing, error) {
|
||||||
|
var product model.ProductEditing
|
||||||
|
|
||||||
|
return &product, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ProductEditingService) SaveProduct(id uint, product *model.ProductEditing) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user