diff --git a/app/module/products/service/products.service.go b/app/module/products/service/products.service.go index d97d267..1b13908 100644 --- a/app/module/products/service/products.service.go +++ b/app/module/products/service/products.service.go @@ -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 } diff --git a/config/toml/config.toml b/config/toml/config.toml index 670b2ad..42be1e2 100644 --- a/config/toml/config.toml +++ b/config/toml/config.toml @@ -49,7 +49,7 @@ enable = true [middleware.limiter] enable = false -max = 20 +max = 500 expiration_seconds = 60 [middleware.csrf]