This commit is contained in:
Aditya Siregar
2025-07-30 23:18:20 +07:00
parent 4a921df55d
commit a759e0f57c
57 changed files with 3633 additions and 190 deletions
+21
View File
@@ -21,6 +21,8 @@ func ProductEntityToModel(entity *entities.Product) *models.Product {
Price: entity.Price,
Cost: entity.Cost,
BusinessType: constants.BusinessType(entity.BusinessType),
ImageURL: entity.ImageURL,
PrinterType: entity.PrinterType,
Metadata: map[string]interface{}(entity.Metadata),
IsActive: entity.IsActive,
CreatedAt: entity.CreatedAt,
@@ -43,6 +45,8 @@ func ProductModelToEntity(model *models.Product) *entities.Product {
Price: model.Price,
Cost: model.Cost,
BusinessType: string(model.BusinessType),
ImageURL: model.ImageURL,
PrinterType: model.PrinterType,
Metadata: entities.Metadata(model.Metadata),
IsActive: model.IsActive,
CreatedAt: model.CreatedAt,
@@ -65,6 +69,11 @@ func CreateProductRequestToEntity(req *models.CreateProductRequest) *entities.Pr
businessType = string(req.BusinessType)
}
printerType := "kitchen"
if req.PrinterType != nil && *req.PrinterType != "" {
printerType = *req.PrinterType
}
metadata := entities.Metadata{}
if req.Metadata != nil {
metadata = entities.Metadata(req.Metadata)
@@ -79,6 +88,8 @@ func CreateProductRequestToEntity(req *models.CreateProductRequest) *entities.Pr
Price: req.Price,
Cost: cost,
BusinessType: businessType,
ImageURL: req.ImageURL,
PrinterType: printerType,
Metadata: metadata,
IsActive: true, // Default to active
}
@@ -117,6 +128,8 @@ func ProductEntityToResponse(entity *entities.Product) *models.ProductResponse {
Price: entity.Price,
Cost: entity.Cost,
BusinessType: constants.BusinessType(entity.BusinessType),
ImageURL: entity.ImageURL,
PrinterType: entity.PrinterType,
Metadata: map[string]interface{}(entity.Metadata),
IsActive: entity.IsActive,
CreatedAt: entity.CreatedAt,
@@ -154,6 +167,14 @@ func UpdateProductEntityFromRequest(entity *entities.Product, req *models.Update
entity.Cost = *req.Cost
}
if req.ImageURL != nil {
entity.ImageURL = req.ImageURL
}
if req.PrinterType != nil {
entity.PrinterType = *req.PrinterType
}
if req.Metadata != nil {
if entity.Metadata == nil {
entity.Metadata = make(entities.Metadata)