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 {
|
type MProductEntity struct {
|
||||||
ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4()" json:"id"`
|
ID uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4()" json:"id"`
|
||||||
Name string `gorm:"type:varchar(255);not null" json:"name"`
|
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"`
|
RefNumber string `gorm:"type:varchar(100);not null;" json:"ref_number"`
|
||||||
SKU string `gorm:"type:varchar(100);not null;uniqueIndex:idx_product_sku_client,priority:1" json:"sku"`
|
SKU string `gorm:"type:varchar(100);not null;" json:"sku"`
|
||||||
Description string `gorm:"type:text" json:"description"`
|
Description string `gorm:"type:text" json:"description"`
|
||||||
Status string `gorm:"type:varchar(50);not null" json:"status"`
|
Status string `gorm:"type:varchar(50);not null" json:"status"`
|
||||||
IsReturnable bool `gorm:"type:boolean;default:false" json:"is_returnable"`
|
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"`
|
MultiplyRate string `gorm:"type:varchar(50)" json:"multiply_rate"`
|
||||||
DivideRate float64 `gorm:"type:decimal(10,2)" json:"divide_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"`
|
ClientID uuid.UUID `gorm:"type:uuid;index;" json:"client_id"`
|
||||||
CategoryID uuid.UUID `gorm:"type:uuid;index" json:"category_id"`
|
CategoryID *uuid.UUID `gorm:"type:uuid;index" json:"category_id"`
|
||||||
UomID uuid.UUID `gorm:"type:uuid;index" json:"uom_id"`
|
UomID *uuid.UUID `gorm:"type:uuid;index" json:"uom_id"`
|
||||||
DimUomID uuid.UUID `gorm:"type:uuid;index" json:"dim_uom_id"`
|
DimUomID *uuid.UUID `gorm:"type:uuid;index" json:"dim_uom_id"`
|
||||||
WeightUomID uuid.UUID `gorm:"type:uuid;index" json:"weight_uom_id"`
|
WeightUomID *uuid.UUID `gorm:"type:uuid;index" json:"weight_uom_id"`
|
||||||
VolumeUomID uuid.UUID `gorm:"type:uuid;index" json:"volume_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"`
|
MinStockUomID *uuid.UUID `gorm:"type:uuid;index" json:"min_stock_uom_id"`
|
||||||
MaxStockUomID uuid.UUID `gorm:"type:uuid;index" json:"max_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"`
|
LeadTimeUomID *uuid.UUID `gorm:"type:uuid;index" json:"lead_time_uom_id"`
|
||||||
UomToUomID uuid.UUID `gorm:"type:uuid;index" json:"uom_to_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;"`
|
Client M_Client `gorm:"foreignKey:ClientID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
|
||||||
Category MCategoryEntity `gorm:"foreignKey:CategoryID;references:ID"`
|
Category MCategoryEntity `gorm:"foreignKey:CategoryID;references:ID"`
|
||||||
|
|
|
||||||
|
|
@ -39,25 +39,25 @@ type (
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Status string `json:"status" binding:"required"`
|
Status string `json:"status" binding:"required"`
|
||||||
IsReturnable bool `json:"is_returnable"`
|
IsReturnable bool `json:"is_returnable"`
|
||||||
DimLength float64 `json:"dim_length"`
|
// DimLength float64 `json:"dim_length"`
|
||||||
DimWidth float64 `json:"dim_width"`
|
// DimWidth float64 `json:"dim_width"`
|
||||||
DimHeight float64 `json:"dim_height"`
|
// DimHeight float64 `json:"dim_height"`
|
||||||
Weight float64 `json:"weight"`
|
// Weight float64 `json:"weight"`
|
||||||
Volume float64 `json:"volume"`
|
// Volume float64 `json:"volume"`
|
||||||
MaxStackHeight int `json:"max_stack_height"`
|
// MaxStackHeight int `json:"max_stack_height"`
|
||||||
Temperature string `json:"temperature"`
|
// Temperature string `json:"temperature"`
|
||||||
IsHazardous bool `json:"is_hazardous"`
|
// IsHazardous bool `json:"is_hazardous"`
|
||||||
MinStock int `json:"min_stock"`
|
// MinStock int `json:"min_stock"`
|
||||||
MaxStock int `json:"max_stock"`
|
// MaxStock int `json:"max_stock"`
|
||||||
ReplenishType string `json:"replenish_type"`
|
// ReplenishType string `json:"replenish_type"`
|
||||||
CycleCount string `json:"cycle_count"`
|
// CycleCount string `json:"cycle_count"`
|
||||||
LotRules string `json:"lot_rules"`
|
// LotRules string `json:"lot_rules"`
|
||||||
LeadTime int `json:"lead_time"`
|
// LeadTime int `json:"lead_time"`
|
||||||
MultiplyRate string `json:"multiply_rate"`
|
// MultiplyRate string `json:"multiply_rate"`
|
||||||
DivideRate float64 `json:"divide_rate"`
|
// DivideRate float64 `json:"divide_rate"`
|
||||||
ClientID string `json:"client_id" binding:"required"`
|
ClientID string `json:"client_id" binding:"required"`
|
||||||
CategoryID string `json:"category_id"`
|
// CategoryID string `json:"category_id"`
|
||||||
UomID string `json:"uom_id"`
|
// UomID string `json:"uom_id"`
|
||||||
// DimUomID string `json:"dim_uom_id"`
|
// DimUomID string `json:"dim_uom_id"`
|
||||||
// WeightUomID string `json:"weight_uom_id"`
|
// WeightUomID string `json:"weight_uom_id"`
|
||||||
// VolumeUomID string `json:"volume_uom_id"`
|
// VolumeUomID string `json:"volume_uom_id"`
|
||||||
|
|
|
||||||
|
|
@ -88,27 +88,27 @@ func (s *productService) Create(ctx context.Context, req dto.ProductCreateReques
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Status: req.Status,
|
Status: req.Status,
|
||||||
IsReturnable: req.IsReturnable,
|
IsReturnable: req.IsReturnable,
|
||||||
DimLength: req.DimLength,
|
// DimLength: req.DimLength,
|
||||||
DimWidth: req.DimWidth,
|
// DimWidth: req.DimWidth,
|
||||||
DimHeight: req.DimHeight,
|
// DimHeight: req.DimHeight,
|
||||||
Weight: req.Weight,
|
// Weight: req.Weight,
|
||||||
Volume: req.Volume,
|
// Volume: req.Volume,
|
||||||
MaxStackHeight: req.MaxStackHeight,
|
// MaxStackHeight: req.MaxStackHeight,
|
||||||
Temperature: req.Temperature,
|
// Temperature: req.Temperature,
|
||||||
IsHazardous: req.IsHazardous,
|
// IsHazardous: req.IsHazardous,
|
||||||
MinStock: req.MinStock,
|
// MinStock: req.MinStock,
|
||||||
MaxStock: req.MaxStock,
|
// MaxStock: req.MaxStock,
|
||||||
ReplenishType: req.ReplenishType,
|
// ReplenishType: req.ReplenishType,
|
||||||
CycleCount: req.CycleCount,
|
// CycleCount: req.CycleCount,
|
||||||
LotRules: req.LotRules,
|
// LotRules: req.LotRules,
|
||||||
LeadTime: req.LeadTime,
|
// LeadTime: req.LeadTime,
|
||||||
MultiplyRate: req.MultiplyRate,
|
// MultiplyRate: req.MultiplyRate,
|
||||||
DivideRate: req.DivideRate,
|
// DivideRate: req.DivideRate,
|
||||||
}
|
}
|
||||||
// UUID fields
|
// UUID fields
|
||||||
product.ClientID = parseUUID(req.ClientID)
|
product.ClientID = parseUUID(req.ClientID)
|
||||||
product.CategoryID = parseUUID(req.CategoryID)
|
// product.CategoryID = parseUUID(req.CategoryID)
|
||||||
product.UomID = parseUUID(req.UomID)
|
// product.UomID = parseUUID(req.UomID)
|
||||||
// product.DimUomID = parseUUID(req.DimUomID)
|
// product.DimUomID = parseUUID(req.DimUomID)
|
||||||
// product.WeightUomID = parseUUID(req.WeightUomID)
|
// product.WeightUomID = parseUUID(req.WeightUomID)
|
||||||
// product.VolumeUomID = parseUUID(req.VolumeUomID)
|
// product.VolumeUomID = parseUUID(req.VolumeUomID)
|
||||||
|
|
@ -236,31 +236,40 @@ func (s *productService) Update(ctx context.Context, req dto.ProductUpdateReques
|
||||||
product.ClientID = parseUUID(*req.ClientID)
|
product.ClientID = parseUUID(*req.ClientID)
|
||||||
}
|
}
|
||||||
if req.CategoryID != nil {
|
if req.CategoryID != nil {
|
||||||
product.CategoryID = parseUUID(*req.CategoryID)
|
id := parseUUID(*req.CategoryID)
|
||||||
|
product.CategoryID = &id
|
||||||
}
|
}
|
||||||
if req.UomID != nil {
|
if req.UomID != nil {
|
||||||
product.UomID = parseUUID(*req.UomID)
|
id := parseUUID(*req.UomID)
|
||||||
|
product.UomID = &id
|
||||||
}
|
}
|
||||||
if req.DimUomID != nil {
|
if req.DimUomID != nil {
|
||||||
product.DimUomID = parseUUID(*req.DimUomID)
|
id := parseUUID(*req.DimUomID)
|
||||||
|
product.DimUomID = &id
|
||||||
}
|
}
|
||||||
if req.WeightUomID != nil {
|
if req.WeightUomID != nil {
|
||||||
product.WeightUomID = parseUUID(*req.WeightUomID)
|
id := parseUUID(*req.WeightUomID)
|
||||||
|
product.WeightUomID = &id
|
||||||
}
|
}
|
||||||
if req.VolumeUomID != nil {
|
if req.VolumeUomID != nil {
|
||||||
product.VolumeUomID = parseUUID(*req.VolumeUomID)
|
id := parseUUID(*req.VolumeUomID)
|
||||||
|
product.VolumeUomID = &id
|
||||||
}
|
}
|
||||||
if req.MinStockUomID != nil {
|
if req.MinStockUomID != nil {
|
||||||
product.MinStockUomID = parseUUID(*req.MinStockUomID)
|
id := parseUUID(*req.MinStockUomID)
|
||||||
|
product.MinStockUomID = &id
|
||||||
}
|
}
|
||||||
if req.MaxStockUomID != nil {
|
if req.MaxStockUomID != nil {
|
||||||
product.MaxStockUomID = parseUUID(*req.MaxStockUomID)
|
id := parseUUID(*req.MaxStockUomID)
|
||||||
|
product.MaxStockUomID = &id
|
||||||
}
|
}
|
||||||
if req.LeadTimeUomID != nil {
|
if req.LeadTimeUomID != nil {
|
||||||
product.LeadTimeUomID = parseUUID(*req.LeadTimeUomID)
|
id := parseUUID(*req.LeadTimeUomID)
|
||||||
|
product.LeadTimeUomID = &id
|
||||||
}
|
}
|
||||||
if req.UomToUomID != nil {
|
if req.UomToUomID != nil {
|
||||||
product.UomToUomID = parseUUID(*req.UomToUomID)
|
id := parseUUID(*req.UomToUomID)
|
||||||
|
product.UomToUomID = &id
|
||||||
}
|
}
|
||||||
updated, err := s.productRepo.Update(ctx, tx, product)
|
updated, err := s.productRepo.Update(ctx, tx, product)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue