feat(product): Refactor ProductCreateRequest and MProductEntity to simplify fields and use pointers for optional IDs
Deploy Application / deploy (push) Successful in 23s
Details
Deploy Application / deploy (push) Successful in 23s
Details
This commit is contained in:
parent
b3d6fad9a6
commit
2c1b645d31
|
|
@ -7,8 +7,8 @@ import (
|
|||
type MProductEntity struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4()" json:"id"`
|
||||
Name string `gorm:"type:varchar(255);not null" json:"name"`
|
||||
RefNumber string `gorm:"type:varchar(100);not null;uniqueIndex:idx_product_refnumber_client,priority:1" json:"ref_number"`
|
||||
SKU string `gorm:"type:varchar(100);not null;uniqueIndex:idx_product_sku_client,priority:1" json:"sku"`
|
||||
RefNumber string `gorm:"type:varchar(100);not null;" json:"ref_number"`
|
||||
SKU string `gorm:"type:varchar(100);not null;" json:"sku"`
|
||||
Description string `gorm:"type:text" json:"description"`
|
||||
Status string `gorm:"type:varchar(50);not null" json:"status"`
|
||||
IsReturnable bool `gorm:"type:boolean;default:false" json:"is_returnable"`
|
||||
|
|
@ -29,16 +29,16 @@ type MProductEntity struct {
|
|||
MultiplyRate string `gorm:"type:varchar(50)" json:"multiply_rate"`
|
||||
DivideRate float64 `gorm:"type:decimal(10,2)" json:"divide_rate"`
|
||||
|
||||
ClientID uuid.UUID `gorm:"type:uuid;index;uniqueIndex:idx_product_refnumber_client,priority:2;uniqueIndex:idx_product_sku_client,priority:2" json:"client_id"`
|
||||
CategoryID uuid.UUID `gorm:"type:uuid;index" json:"category_id"`
|
||||
UomID uuid.UUID `gorm:"type:uuid;index" json:"uom_id"`
|
||||
DimUomID uuid.UUID `gorm:"type:uuid;index" json:"dim_uom_id"`
|
||||
WeightUomID uuid.UUID `gorm:"type:uuid;index" json:"weight_uom_id"`
|
||||
VolumeUomID uuid.UUID `gorm:"type:uuid;index" json:"volume_uom_id"`
|
||||
MinStockUomID uuid.UUID `gorm:"type:uuid;index" json:"min_stock_uom_id"`
|
||||
MaxStockUomID uuid.UUID `gorm:"type:uuid;index" json:"max_stock_uom_id"`
|
||||
LeadTimeUomID uuid.UUID `gorm:"type:uuid;index" json:"lead_time_uom_id"`
|
||||
UomToUomID uuid.UUID `gorm:"type:uuid;index" json:"uom_to_uom_id"`
|
||||
ClientID uuid.UUID `gorm:"type:uuid;index;" json:"client_id"`
|
||||
CategoryID *uuid.UUID `gorm:"type:uuid;index" json:"category_id"`
|
||||
UomID *uuid.UUID `gorm:"type:uuid;index" json:"uom_id"`
|
||||
DimUomID *uuid.UUID `gorm:"type:uuid;index" json:"dim_uom_id"`
|
||||
WeightUomID *uuid.UUID `gorm:"type:uuid;index" json:"weight_uom_id"`
|
||||
VolumeUomID *uuid.UUID `gorm:"type:uuid;index" json:"volume_uom_id"`
|
||||
MinStockUomID *uuid.UUID `gorm:"type:uuid;index" json:"min_stock_uom_id"`
|
||||
MaxStockUomID *uuid.UUID `gorm:"type:uuid;index" json:"max_stock_uom_id"`
|
||||
LeadTimeUomID *uuid.UUID `gorm:"type:uuid;index" json:"lead_time_uom_id"`
|
||||
UomToUomID *uuid.UUID `gorm:"type:uuid;index" json:"uom_to_uom_id"`
|
||||
|
||||
Client M_Client `gorm:"foreignKey:ClientID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
|
||||
Category MCategoryEntity `gorm:"foreignKey:CategoryID;references:ID"`
|
||||
|
|
|
|||
|
|
@ -33,31 +33,31 @@ var (
|
|||
|
||||
type (
|
||||
ProductCreateRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
RefNumber string `json:"ref_number" binding:"required"`
|
||||
SKU string `json:"sku" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Status string `json:"status" binding:"required"`
|
||||
IsReturnable bool `json:"is_returnable"`
|
||||
DimLength float64 `json:"dim_length"`
|
||||
DimWidth float64 `json:"dim_width"`
|
||||
DimHeight float64 `json:"dim_height"`
|
||||
Weight float64 `json:"weight"`
|
||||
Volume float64 `json:"volume"`
|
||||
MaxStackHeight int `json:"max_stack_height"`
|
||||
Temperature string `json:"temperature"`
|
||||
IsHazardous bool `json:"is_hazardous"`
|
||||
MinStock int `json:"min_stock"`
|
||||
MaxStock int `json:"max_stock"`
|
||||
ReplenishType string `json:"replenish_type"`
|
||||
CycleCount string `json:"cycle_count"`
|
||||
LotRules string `json:"lot_rules"`
|
||||
LeadTime int `json:"lead_time"`
|
||||
MultiplyRate string `json:"multiply_rate"`
|
||||
DivideRate float64 `json:"divide_rate"`
|
||||
ClientID string `json:"client_id" binding:"required"`
|
||||
CategoryID string `json:"category_id"`
|
||||
UomID string `json:"uom_id"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
RefNumber string `json:"ref_number" binding:"required"`
|
||||
SKU string `json:"sku" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
Status string `json:"status" binding:"required"`
|
||||
IsReturnable bool `json:"is_returnable"`
|
||||
// DimLength float64 `json:"dim_length"`
|
||||
// DimWidth float64 `json:"dim_width"`
|
||||
// DimHeight float64 `json:"dim_height"`
|
||||
// Weight float64 `json:"weight"`
|
||||
// Volume float64 `json:"volume"`
|
||||
// MaxStackHeight int `json:"max_stack_height"`
|
||||
// Temperature string `json:"temperature"`
|
||||
// IsHazardous bool `json:"is_hazardous"`
|
||||
// MinStock int `json:"min_stock"`
|
||||
// MaxStock int `json:"max_stock"`
|
||||
// ReplenishType string `json:"replenish_type"`
|
||||
// CycleCount string `json:"cycle_count"`
|
||||
// LotRules string `json:"lot_rules"`
|
||||
// LeadTime int `json:"lead_time"`
|
||||
// MultiplyRate string `json:"multiply_rate"`
|
||||
// DivideRate float64 `json:"divide_rate"`
|
||||
ClientID string `json:"client_id" binding:"required"`
|
||||
// CategoryID string `json:"category_id"`
|
||||
// UomID string `json:"uom_id"`
|
||||
// DimUomID string `json:"dim_uom_id"`
|
||||
// WeightUomID string `json:"weight_uom_id"`
|
||||
// VolumeUomID string `json:"volume_uom_id"`
|
||||
|
|
|
|||
|
|
@ -82,33 +82,33 @@ func (s *productService) Create(ctx context.Context, req dto.ProductCreateReques
|
|||
}
|
||||
}()
|
||||
product := entities.MProductEntity{
|
||||
Name: req.Name,
|
||||
RefNumber: req.RefNumber,
|
||||
SKU: req.SKU,
|
||||
Description: req.Description,
|
||||
Status: req.Status,
|
||||
IsReturnable: req.IsReturnable,
|
||||
DimLength: req.DimLength,
|
||||
DimWidth: req.DimWidth,
|
||||
DimHeight: req.DimHeight,
|
||||
Weight: req.Weight,
|
||||
Volume: req.Volume,
|
||||
MaxStackHeight: req.MaxStackHeight,
|
||||
Temperature: req.Temperature,
|
||||
IsHazardous: req.IsHazardous,
|
||||
MinStock: req.MinStock,
|
||||
MaxStock: req.MaxStock,
|
||||
ReplenishType: req.ReplenishType,
|
||||
CycleCount: req.CycleCount,
|
||||
LotRules: req.LotRules,
|
||||
LeadTime: req.LeadTime,
|
||||
MultiplyRate: req.MultiplyRate,
|
||||
DivideRate: req.DivideRate,
|
||||
Name: req.Name,
|
||||
RefNumber: req.RefNumber,
|
||||
SKU: req.SKU,
|
||||
Description: req.Description,
|
||||
Status: req.Status,
|
||||
IsReturnable: req.IsReturnable,
|
||||
// DimLength: req.DimLength,
|
||||
// DimWidth: req.DimWidth,
|
||||
// DimHeight: req.DimHeight,
|
||||
// Weight: req.Weight,
|
||||
// Volume: req.Volume,
|
||||
// MaxStackHeight: req.MaxStackHeight,
|
||||
// Temperature: req.Temperature,
|
||||
// IsHazardous: req.IsHazardous,
|
||||
// MinStock: req.MinStock,
|
||||
// MaxStock: req.MaxStock,
|
||||
// ReplenishType: req.ReplenishType,
|
||||
// CycleCount: req.CycleCount,
|
||||
// LotRules: req.LotRules,
|
||||
// LeadTime: req.LeadTime,
|
||||
// MultiplyRate: req.MultiplyRate,
|
||||
// DivideRate: req.DivideRate,
|
||||
}
|
||||
// UUID fields
|
||||
product.ClientID = parseUUID(req.ClientID)
|
||||
product.CategoryID = parseUUID(req.CategoryID)
|
||||
product.UomID = parseUUID(req.UomID)
|
||||
// product.CategoryID = parseUUID(req.CategoryID)
|
||||
// product.UomID = parseUUID(req.UomID)
|
||||
// product.DimUomID = parseUUID(req.DimUomID)
|
||||
// product.WeightUomID = parseUUID(req.WeightUomID)
|
||||
// product.VolumeUomID = parseUUID(req.VolumeUomID)
|
||||
|
|
@ -236,31 +236,40 @@ func (s *productService) Update(ctx context.Context, req dto.ProductUpdateReques
|
|||
product.ClientID = parseUUID(*req.ClientID)
|
||||
}
|
||||
if req.CategoryID != nil {
|
||||
product.CategoryID = parseUUID(*req.CategoryID)
|
||||
id := parseUUID(*req.CategoryID)
|
||||
product.CategoryID = &id
|
||||
}
|
||||
if req.UomID != nil {
|
||||
product.UomID = parseUUID(*req.UomID)
|
||||
id := parseUUID(*req.UomID)
|
||||
product.UomID = &id
|
||||
}
|
||||
if req.DimUomID != nil {
|
||||
product.DimUomID = parseUUID(*req.DimUomID)
|
||||
id := parseUUID(*req.DimUomID)
|
||||
product.DimUomID = &id
|
||||
}
|
||||
if req.WeightUomID != nil {
|
||||
product.WeightUomID = parseUUID(*req.WeightUomID)
|
||||
id := parseUUID(*req.WeightUomID)
|
||||
product.WeightUomID = &id
|
||||
}
|
||||
if req.VolumeUomID != nil {
|
||||
product.VolumeUomID = parseUUID(*req.VolumeUomID)
|
||||
id := parseUUID(*req.VolumeUomID)
|
||||
product.VolumeUomID = &id
|
||||
}
|
||||
if req.MinStockUomID != nil {
|
||||
product.MinStockUomID = parseUUID(*req.MinStockUomID)
|
||||
id := parseUUID(*req.MinStockUomID)
|
||||
product.MinStockUomID = &id
|
||||
}
|
||||
if req.MaxStockUomID != nil {
|
||||
product.MaxStockUomID = parseUUID(*req.MaxStockUomID)
|
||||
id := parseUUID(*req.MaxStockUomID)
|
||||
product.MaxStockUomID = &id
|
||||
}
|
||||
if req.LeadTimeUomID != nil {
|
||||
product.LeadTimeUomID = parseUUID(*req.LeadTimeUomID)
|
||||
id := parseUUID(*req.LeadTimeUomID)
|
||||
product.LeadTimeUomID = &id
|
||||
}
|
||||
if req.UomToUomID != nil {
|
||||
product.UomToUomID = parseUUID(*req.UomToUomID)
|
||||
id := parseUUID(*req.UomToUomID)
|
||||
product.UomToUomID = &id
|
||||
}
|
||||
updated, err := s.productRepo.Update(ctx, tx, product)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue