chore: address pull request review issues
This commit is contained in:
@@ -2,27 +2,27 @@ package middleware
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
|
||||||
|
"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"
|
"github.com/gofiber/fiber/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Require(p perms.Permission) fiber.Handler {
|
func Require(p perms.Permission) fiber.Handler {
|
||||||
return func(c fiber.Ctx) error {
|
return func(c fiber.Ctx) error {
|
||||||
u := c.Locals("user")
|
user, ok := localeExtractor.GetCustomer(c)
|
||||||
if u == nil {
|
|
||||||
return c.SendStatus(fiber.StatusUnauthorized)
|
|
||||||
}
|
|
||||||
|
|
||||||
user, ok := u.(*model.UserSession)
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return c.SendStatus(fiber.StatusInternalServerError)
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, perm := range user.Permissions {
|
for _, perm := range user.Role.Permissions {
|
||||||
if perm == p {
|
if perm.Name == p {
|
||||||
return c.Next()
|
return c.Next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c.SendStatus(fiber.StatusForbidden)
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrForbidden)).
|
||||||
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrForbidden)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ const (
|
|||||||
UserWriteAny Permission = "user.write.any"
|
UserWriteAny Permission = "user.write.any"
|
||||||
UserDeleteAny Permission = "user.delete.any"
|
UserDeleteAny Permission = "user.delete.any"
|
||||||
CurrencyWrite Permission = "currency.write"
|
CurrencyWrite Permission = "currency.write"
|
||||||
|
SpecificPriceManage Permission = "specific_price.manage"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model/dbmodel"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/productService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/productService"
|
||||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
|
||||||
@@ -82,7 +82,7 @@ func (h *ProductsHandler) GetProductJson(c fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *ProductsHandler) ListProducts(c fiber.Ctx) error {
|
func (h *ProductsHandler) ListProducts(c fiber.Ctx) error {
|
||||||
paging, filters, err := query_params.ParseFilters[model.Product](c, columnMappingListProducts)
|
paging, filters, err := query_params.ParseFilters[dbmodel.PsProduct](c, columnMappingListProducts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
@@ -94,7 +94,7 @@ func (h *ProductsHandler) ListProducts(c fiber.Ctx) error {
|
|||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := h.productService.Find(customer.LangID, customer.ID, paging, filters, customer, 1, constdata.SHOP_ID)
|
list, err := h.productService.Find(customer.LangID, customer.ID, paging, filters, customer, constdata.DEFAULT_PRODUCT_QUANTITY, constdata.SHOP_ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
@@ -176,7 +176,7 @@ func (h *ProductsHandler) ListProductVariants(c fiber.Ctx) error {
|
|||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := h.productService.GetProductAttributes(customer.LangID, uint(productID), constdata.SHOP_ID, customer.ID, customer.CountryID, 1)
|
list, err := h.productService.GetProductAttributes(customer.LangID, uint(productID), constdata.SHOP_ID, customer.ID, customer.CountryID, constdata.DEFAULT_PRODUCT_QUANTITY)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ package restricted
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||||
|
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||||
"git.ma-al.com/goc_daniel/b2b/app/service/specificPriceService"
|
"git.ma-al.com/goc_daniel/b2b/app/service/specificPriceService"
|
||||||
|
"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"
|
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
)
|
)
|
||||||
@@ -27,13 +30,13 @@ func NewSpecificPriceHandler() *SpecificPriceHandler {
|
|||||||
func SpecificPriceHandlerRoutes(r fiber.Router) fiber.Router {
|
func SpecificPriceHandlerRoutes(r fiber.Router) fiber.Router {
|
||||||
handler := NewSpecificPriceHandler()
|
handler := NewSpecificPriceHandler()
|
||||||
|
|
||||||
r.Post("/", handler.Create)
|
r.Post("/", middleware.Require("specific_price.manage"), handler.Create)
|
||||||
r.Put("/:id", handler.Update)
|
r.Put("/:id", middleware.Require("specific_price.manage"), handler.Update)
|
||||||
r.Delete("/:id", handler.Delete)
|
r.Delete("/:id", middleware.Require("specific_price.manage"), handler.Delete)
|
||||||
r.Get("/", handler.List)
|
r.Get("/", middleware.Require("specific_price.manage"), handler.List)
|
||||||
r.Get("/:id", handler.GetByID)
|
r.Get("/:id", middleware.Require("specific_price.manage"), handler.GetByID)
|
||||||
r.Patch("/:id/activate", handler.Activate)
|
r.Patch("/:id/activate", middleware.Require("specific_price.manage"), handler.Activate)
|
||||||
r.Patch("/:id/deactivate", handler.Deactivate)
|
r.Patch("/:id/deactivate", middleware.Require("specific_price.manage"), handler.Deactivate)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -41,147 +44,116 @@ func SpecificPriceHandlerRoutes(r fiber.Router) fiber.Router {
|
|||||||
func (h *SpecificPriceHandler) Create(c fiber.Ctx) error {
|
func (h *SpecificPriceHandler) Create(c fiber.Ctx) error {
|
||||||
var pr model.SpecificPrice
|
var pr model.SpecificPrice
|
||||||
if err := c.Bind().Body(&pr); err != nil {
|
if err := c.Bind().Body(&pr); err != nil {
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
"error": responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := h.SpecificPriceService.Create(c.Context(), &pr)
|
result, err := h.SpecificPriceService.Create(c.Context(), &pr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
"error": responseErrors.GetErrorCode(c, err),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Status(fiber.StatusCreated).JSON(result)
|
return c.JSON(response.Make(&result, 1, i18n.T_(c, response.Message_OK)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *SpecificPriceHandler) Update(c fiber.Ctx) error {
|
func (h *SpecificPriceHandler) Update(c fiber.Ctx) error {
|
||||||
idStr := c.Params("id")
|
idStr := c.Params("id")
|
||||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
"error": responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var pr model.SpecificPrice
|
var pr model.SpecificPrice
|
||||||
if err := c.Bind().Body(&pr); err != nil {
|
if err := c.Bind().Body(&pr); err != nil {
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||||
"error": responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := h.SpecificPriceService.Update(c.Context(), id, &pr)
|
result, err := h.SpecificPriceService.Update(c.Context(), id, &pr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
"error": responseErrors.GetErrorCode(c, err),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(result)
|
return c.JSON(response.Make(&result, 1, i18n.T_(c, response.Message_OK)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *SpecificPriceHandler) List(c fiber.Ctx) error {
|
func (h *SpecificPriceHandler) List(c fiber.Ctx) error {
|
||||||
result, err := h.SpecificPriceService.List(c.Context())
|
result, err := h.SpecificPriceService.List(c.Context())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
"error": responseErrors.GetErrorCode(c, err),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(result)
|
return c.JSON(response.Make(&result, 1, i18n.T_(c, response.Message_OK)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *SpecificPriceHandler) GetByID(c fiber.Ctx) error {
|
func (h *SpecificPriceHandler) GetByID(c fiber.Ctx) error {
|
||||||
idStr := c.Params("id")
|
idStr := c.Params("id")
|
||||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
"error": responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := h.SpecificPriceService.GetByID(c.Context(), id)
|
result, err := h.SpecificPriceService.GetByID(c.Context(), id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
"error": responseErrors.GetErrorCode(c, err),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(result)
|
return c.JSON(response.Make(&result, 1, i18n.T_(c, response.Message_OK)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *SpecificPriceHandler) Activate(c fiber.Ctx) error {
|
func (h *SpecificPriceHandler) Activate(c fiber.Ctx) error {
|
||||||
idStr := c.Params("id")
|
idStr := c.Params("id")
|
||||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
"error": responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.SpecificPriceService.SetActive(c.Context(), id, true)
|
err = h.SpecificPriceService.SetActive(c.Context(), id, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
"error": responseErrors.GetErrorCode(c, err),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(fiber.Map{
|
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
|
||||||
"message": "price reduction activated",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *SpecificPriceHandler) Deactivate(c fiber.Ctx) error {
|
func (h *SpecificPriceHandler) Deactivate(c fiber.Ctx) error {
|
||||||
idStr := c.Params("id")
|
idStr := c.Params("id")
|
||||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
"error": responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.SpecificPriceService.SetActive(c.Context(), id, false)
|
err = h.SpecificPriceService.SetActive(c.Context(), id, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
"error": responseErrors.GetErrorCode(c, err),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(fiber.Map{
|
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
|
||||||
"message": "price reduction deactivated",
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *SpecificPriceHandler) Delete(c fiber.Ctx) error {
|
func (h *SpecificPriceHandler) Delete(c fiber.Ctx) error {
|
||||||
idStr := c.Params("id")
|
idStr := c.Params("id")
|
||||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||||
"error": responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.SpecificPriceService.Delete(c.Context(), id)
|
err = h.SpecificPriceService.Delete(c.Context(), id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||||
"error": responseErrors.GetErrorCode(c, err),
|
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(fiber.Map{
|
return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK)))
|
||||||
"message": "specific price deleted",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseTime(s *string) *time.Time {
|
|
||||||
if s == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
t, err := time.Parse(time.RFC3339, *s)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &t
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,66 +1,5 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
// Product contains each and every column from the table ps_product.
|
|
||||||
type Product struct {
|
|
||||||
ProductID uint `gorm:"column:id_product;primaryKey" json:"product_id" form:"product_id"`
|
|
||||||
SupplierID uint `gorm:"column:id_supplier" json:"supplier_id" form:"supplier_id"`
|
|
||||||
ManufacturerID uint `gorm:"column:id_manufacturer" json:"manufacturer_id" form:"manufacturer_id"`
|
|
||||||
CategoryDefaultID uint `gorm:"column:id_category_default" json:"category_default_id" form:"category_default_id"`
|
|
||||||
ShopDefaultID uint `gorm:"column:id_shop_default" json:"shop_default_id" form:"shop_default_id"`
|
|
||||||
TaxRulesGroupID uint `gorm:"column:id_tax_rules_group" json:"tax_rules_group_id" form:"tax_rules_group_id"`
|
|
||||||
OnSale uint `gorm:"column:on_sale" json:"on_sale" form:"on_sale"`
|
|
||||||
OnlineOnly uint `gorm:"column:online_only" json:"online_only" form:"online_only"`
|
|
||||||
EAN13 string `gorm:"column:ean13;type:varchar(13)" json:"ean13" form:"ean13"`
|
|
||||||
ISBN string `gorm:"column:isbn;type:varchar(32)" json:"isbn" form:"isbn"`
|
|
||||||
UPC string `gorm:"column:upc;type:varchar(12)" json:"upc" form:"upc"`
|
|
||||||
EkoTax float32 `gorm:"column:eko_tax;type:decimal(20,6)" json:"eko_tax" form:"eko_tax"`
|
|
||||||
Quantity uint `gorm:"column:quantity" json:"quantity" form:"quantity"`
|
|
||||||
MinimalQuantity uint `gorm:"column:minimal_quantity" json:"minimal_quantity" form:"minimal_quantity"`
|
|
||||||
LowStockThreshold uint `gorm:"column:low_stock_threshold" json:"low_stock_threshold" form:"low_stock_threshold"`
|
|
||||||
LowStockAlert uint `gorm:"column:low_stock_alert" json:"low_stock_alert" form:"low_stock_alert"`
|
|
||||||
Price float32 `gorm:"column:price;type:decimal(20,6)" json:"price" form:"price"`
|
|
||||||
WholesalePrice float32 `gorm:"column:wholesale_price;type:decimal(20,6)" json:"wholesale_price" form:"wholesale_price"`
|
|
||||||
Unity string `gorm:"column:unity;type:varchar(255)" json:"unity" form:"unity"`
|
|
||||||
UnitPriceRatio float32 `gorm:"column:unit_price_ratio;type:decimal(20,6)" json:"unit_price_ratio" form:"unit_price_ratio"`
|
|
||||||
UnitID uint `gorm:"column:id_unit;primaryKey" json:"unit_id" form:"unit_id"`
|
|
||||||
AdditionalShippingCost float32 `gorm:"column:additional_shipping_cost;type:decimal(20,2)" json:"additional_shipping_cost" form:"additional_shipping_cost"`
|
|
||||||
Reference string `gorm:"column:reference;type:varchar(64)" json:"reference" form:"reference"`
|
|
||||||
SupplierReference string `gorm:"column:supplier_reference;type:varchar(64)" json:"supplier_reference" form:"supplier_reference"`
|
|
||||||
Location string `gorm:"column:location;type:varchar(64)" json:"location" form:"location"`
|
|
||||||
|
|
||||||
Width float32 `gorm:"column:width;type:decimal(20,6)" json:"width" form:"width"`
|
|
||||||
Height float32 `gorm:"column:height;type:decimal(20,6)" json:"height" form:"height"`
|
|
||||||
Depth float32 `gorm:"column:depth;type:decimal(20,6)" json:"depth" form:"depth"`
|
|
||||||
Weight float32 `gorm:"column:weight;type:decimal(20,6)" json:"weight" form:"weight"`
|
|
||||||
OutOfStock uint `gorm:"column:out_of_stock" json:"out_of_stock" form:"out_of_stock"`
|
|
||||||
AdditionalDeliveryTimes uint `gorm:"column:additional_delivery_times" json:"additional_delivery_times" form:"additional_delivery_times"`
|
|
||||||
QuantityDiscount uint `gorm:"column:quantity_discount" json:"quantity_discount" form:"quantity_discount"`
|
|
||||||
Customizable uint `gorm:"column:customizable" json:"customizable" form:"customizable"`
|
|
||||||
UploadableFiles uint `gorm:"column:uploadable_files" json:"uploadable_files" form:"uploadable_files"`
|
|
||||||
TextFields uint `gorm:"column:text_fields" json:"text_fields" form:"text_fields"`
|
|
||||||
|
|
||||||
Active uint `gorm:"column:active" json:"active" form:"active"`
|
|
||||||
RedirectType string `gorm:"column:redirect_type;type:enum('','404','301-product','302-product','301-category','302-category')" json:"redirect_type" form:"redirect_type"`
|
|
||||||
TypeRedirectedID int `gorm:"column:id_type_redirected" json:"type_redirected_id" form:"type_redirected_id"`
|
|
||||||
AvailableForOrder uint `gorm:"column:available_for_order" json:"available_for_order" form:"available_for_order"`
|
|
||||||
AvailableDate string `gorm:"column:available_date;type:date" json:"available_date" form:"available_date"`
|
|
||||||
ShowCondition uint `gorm:"column:show_condition" json:"show_condition" form:"show_condition"`
|
|
||||||
Condition string `gorm:"column:condition;type:enum('new','used','refurbished')" json:"condition" form:"condition"`
|
|
||||||
ShowPrice uint `gorm:"column:show_price" json:"show_price" form:"show_price"`
|
|
||||||
|
|
||||||
Indexed uint `gorm:"column:indexed" json:"indexed" form:"indexed"`
|
|
||||||
Visibility string `gorm:"column:visibility;type:enum('both','catalog','search','none')" json:"visibility" form:"visibility"`
|
|
||||||
CacheIsPack uint `gorm:"column:cache_is_pack" json:"cache_is_pack" form:"cache_is_pack"`
|
|
||||||
CacheHasAttachments uint `gorm:"column:cache_has_attachments" json:"cache_has_attachments" form:"cache_has_attachments"`
|
|
||||||
IsVirtual uint `gorm:"column:is_virtual" json:"is_virtual" form:"is_virtual"`
|
|
||||||
CacheDefaultAttribute uint `gorm:"column:cache_default_attribute" json:"cache_default_attribute" form:"cache_default_attribute"`
|
|
||||||
DateAdd string `gorm:"column:date_add;type:datetime" json:"date_add" form:"date_add"`
|
|
||||||
DateUpd string `gorm:"column:date_upd;type:datetime" json:"date_upd" form:"date_upd"`
|
|
||||||
AdvancedStockManagement uint `gorm:"column:advanced_stock_management" json:"advanced_stock_management" form:"advanced_stock_management"`
|
|
||||||
PackStockType uint `gorm:"column:pack_stock_type" json:"pack_stock_type" form:"pack_stock_type"`
|
|
||||||
State uint `gorm:"column:state" json:"state" form:"state"`
|
|
||||||
DeliveryDays uint `gorm:"column:delivery_days" json:"delivery_days" form:"delivery_days"`
|
|
||||||
}
|
|
||||||
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"`
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import "time"
|
|||||||
type SpecificPrice struct {
|
type SpecificPrice struct {
|
||||||
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||||
Name string `gorm:"type:varchar(255);not null" json:"name"`
|
Name string `gorm:"type:varchar(255);not null" json:"name"`
|
||||||
Scope string `gorm:"type:varchar(20);not null" json:"scope"`
|
|
||||||
ValidFrom *time.Time `gorm:"null" json:"valid_from"`
|
ValidFrom *time.Time `gorm:"null" json:"valid_from"`
|
||||||
ValidTill *time.Time `gorm:"null" json:"valid_till"`
|
ValidTill *time.Time `gorm:"null" json:"valid_till"`
|
||||||
HasExpirationDate bool `gorm:"default:false" json:"has_expiration_date"`
|
HasExpirationDate bool `gorm:"default:false" json:"has_expiration_date"`
|
||||||
|
|||||||
@@ -23,12 +23,6 @@ func (s *SpecificPriceService) Create(ctx context.Context, pr *model.SpecificPri
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if pr.Scope == "shop" && len(pr.ProductIDs) == 0 && len(pr.CategoryIDs) == 0 && len(pr.ProductAttributeIDs) == 0 && len(pr.CountryIDs) == 0 && len(pr.CustomerIDs) == 0 {
|
|
||||||
// pr.Scope = "global"
|
|
||||||
} else {
|
|
||||||
// pr.Scope = "scoped"
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.specificPriceRepo.Create(ctx, pr); err != nil {
|
if err := s.specificPriceRepo.Create(ctx, pr); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -51,12 +45,6 @@ func (s *SpecificPriceService) Update(ctx context.Context, id uint64, pr *model.
|
|||||||
|
|
||||||
pr.ID = id
|
pr.ID = id
|
||||||
|
|
||||||
if pr.Scope == "shop" && len(pr.ProductIDs) == 0 && len(pr.CategoryIDs) == 0 && len(pr.ProductAttributeIDs) == 0 && len(pr.CountryIDs) == 0 && len(pr.CustomerIDs) == 0 {
|
|
||||||
// pr.Scope = "global"
|
|
||||||
} else {
|
|
||||||
// pr.Scope = "scoped"
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.specificPriceRepo.Update(ctx, pr); err != nil {
|
if err := s.specificPriceRepo.Update(ctx, pr); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package constdata
|
|||||||
// PASSWORD_VALIDATION_REGEX is used by the frontend (JavaScript supports lookaheads).
|
// PASSWORD_VALIDATION_REGEX is used by the frontend (JavaScript supports lookaheads).
|
||||||
const PASSWORD_VALIDATION_REGEX = `^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{10,}$`
|
const PASSWORD_VALIDATION_REGEX = `^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{10,}$`
|
||||||
const SHOP_ID = 1
|
const SHOP_ID = 1
|
||||||
|
const DEFAULT_PRODUCT_QUANTITY = 1
|
||||||
const SHOP_DEFAULT_LANGUAGE = 1
|
const SHOP_DEFAULT_LANGUAGE = 1
|
||||||
const ADMIN_NOTIFICATION_LANGUAGE = 2
|
const ADMIN_NOTIFICATION_LANGUAGE = 2
|
||||||
|
|
||||||
|
|||||||
@@ -285,7 +285,6 @@ func GetErrorStatus(err error) int {
|
|||||||
errors.Is(err, ErrInvalidReductionType),
|
errors.Is(err, ErrInvalidReductionType),
|
||||||
errors.Is(err, ErrPercentageRequired),
|
errors.Is(err, ErrPercentageRequired),
|
||||||
errors.Is(err, ErrPriceRequired),
|
errors.Is(err, ErrPriceRequired),
|
||||||
errors.Is(err, ErrJSONBody),
|
|
||||||
errors.Is(err, ErrAccessDenied),
|
errors.Is(err, ErrAccessDenied),
|
||||||
errors.Is(err, ErrFolderDoesNotExist),
|
errors.Is(err, ErrFolderDoesNotExist),
|
||||||
errors.Is(err, ErrFileDoesNotExist),
|
errors.Is(err, ErrFileDoesNotExist),
|
||||||
|
|||||||
@@ -238,7 +238,6 @@ CREATE TABLE b2b_specific_price (
|
|||||||
created_at DATETIME NULL,
|
created_at DATETIME NULL,
|
||||||
updated_at DATETIME NULL,
|
updated_at DATETIME NULL,
|
||||||
deleted_at DATETIME NULL,
|
deleted_at DATETIME NULL,
|
||||||
scope ENUM('shop', 'category', 'product') NOT NULL,
|
|
||||||
valid_from DATETIME NULL,
|
valid_from DATETIME NULL,
|
||||||
valid_till DATETIME NULL,
|
valid_till DATETIME NULL,
|
||||||
has_expiration_date BOOLEAN DEFAULT FALSE,
|
has_expiration_date BOOLEAN DEFAULT FALSE,
|
||||||
@@ -249,11 +248,9 @@ CREATE TABLE b2b_specific_price (
|
|||||||
from_quantity INT UNSIGNED DEFAULT 1,
|
from_quantity INT UNSIGNED DEFAULT 1,
|
||||||
is_active BOOLEAN DEFAULT TRUE
|
is_active BOOLEAN DEFAULT TRUE
|
||||||
) ENGINE = InnoDB;
|
) ENGINE = InnoDB;
|
||||||
CREATE INDEX idx_b2b_scope ON b2b_specific_price(scope);
|
|
||||||
CREATE INDEX idx_b2b_active_dates ON b2b_specific_price(is_active, valid_from, valid_till);
|
CREATE INDEX idx_b2b_active_dates ON b2b_specific_price(is_active, valid_from, valid_till);
|
||||||
CREATE INDEX idx_b2b_lookup
|
CREATE INDEX idx_b2b_lookup
|
||||||
ON b2b_specific_price (
|
ON b2b_specific_price (
|
||||||
scope,
|
|
||||||
is_active,
|
is_active,
|
||||||
from_quantity
|
from_quantity
|
||||||
);
|
);
|
||||||
@@ -307,11 +304,11 @@ ON b2b_specific_price_category (id_category);
|
|||||||
CREATE INDEX idx_b2b_product_attribute_rel
|
CREATE INDEX idx_b2b_product_attribute_rel
|
||||||
ON b2b_specific_price_product_attribute (id_product_attribute);
|
ON b2b_specific_price_product_attribute (id_product_attribute);
|
||||||
|
|
||||||
CREATE INDEX idx_bsp_customer
|
CREATE INDEX idx_bsp_customer_rel
|
||||||
ON b2b_specific_price_customer (b2b_specific_price_id, b2b_id_customer);
|
ON b2b_specific_price_customer (b2b_id_customer);
|
||||||
|
|
||||||
CREATE INDEX idx_bsp_country
|
CREATE INDEX idx_bsp_country_rel
|
||||||
ON b2b_specific_price_country (b2b_specific_price_id, b2b_id_country);
|
ON b2b_specific_price_country (b2b_id_country);
|
||||||
|
|
||||||
DELIMITER //
|
DELIMITER //
|
||||||
|
|
||||||
|
|||||||
@@ -34,13 +34,16 @@ INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('1', 'user.read.any');
|
|||||||
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('2', 'user.write.any');
|
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('2', 'user.write.any');
|
||||||
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('3', 'user.delete.any');
|
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('3', 'user.delete.any');
|
||||||
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('4', 'currency.write');
|
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('4', 'currency.write');
|
||||||
|
INSERT INTO `b2b_permissions` (`id`, `name`) VALUES ('5', 'specific_price.manage');
|
||||||
|
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '1');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '1');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '2');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '2');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '3');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '3');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '4');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '4');
|
||||||
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('2', '5');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '1');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '1');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '2');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '2');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '3');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '3');
|
||||||
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '4');
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '4');
|
||||||
|
INSERT INTO `b2b_role_permissions` (`role_id`, `permission_id`) VALUES ('3', '5');
|
||||||
-- +goose Down
|
-- +goose Down
|
||||||
Reference in New Issue
Block a user