This commit is contained in:
Anang Yusman 2026-01-27 14:01:19 +08:00
parent a2cdb34bc3
commit 849d353736
2 changed files with 23 additions and 2 deletions

View File

@ -22,11 +22,14 @@ import (
"strings"
"time"
"encoding/json"
"github.com/gofiber/fiber/v2"
"github.com/minio/minio-go/v7"
"github.com/rs/zerolog"
)
type productsService struct {
Repo repository.ProductsRepository
Log zerolog.Logger
@ -98,17 +101,35 @@ func (_i *productsService) Create(c *fiber.Ctx, req request.ProductsCreateReques
req.ThumbnailPath = filePath
}
// 🔥 CONVERT REQUEST KE ENTITY
productEntity := req.ToEntity()
// 🔥 FIX COLORS (INI INTI MASALAH KAMU)
var colors []string
for _, c := range req.Colors {
if c.Name != "" {
colors = append(colors, c.Name)
}
}
if len(colors) > 0 {
bytes, _ := json.Marshal(colors)
colorStr := string(bytes)
productEntity.Colors = &colorStr
}
// SET DEFAULT ACTIVE
isActive := true
productEntity.IsActive = &isActive
// 🔥 SIMPAN KE DATABASE
productEntity, err = _i.Repo.Create(productEntity)
if err != nil {
return
}
host := _i.Cfg.App.Domain
product = mapper.ProductsResponseMapper(productEntity, host)
return
}

View File

@ -49,7 +49,7 @@ enable = true
[middleware.limiter]
enable = false
max = 20
max = 500
expiration_seconds = 60
[middleware.csrf]