update
This commit is contained in:
parent
a2cdb34bc3
commit
849d353736
|
|
@ -22,11 +22,14 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type productsService struct {
|
type productsService struct {
|
||||||
Repo repository.ProductsRepository
|
Repo repository.ProductsRepository
|
||||||
Log zerolog.Logger
|
Log zerolog.Logger
|
||||||
|
|
@ -98,17 +101,35 @@ func (_i *productsService) Create(c *fiber.Ctx, req request.ProductsCreateReques
|
||||||
req.ThumbnailPath = filePath
|
req.ThumbnailPath = filePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 🔥 CONVERT REQUEST KE ENTITY
|
||||||
productEntity := req.ToEntity()
|
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
|
isActive := true
|
||||||
productEntity.IsActive = &isActive
|
productEntity.IsActive = &isActive
|
||||||
|
|
||||||
|
// 🔥 SIMPAN KE DATABASE
|
||||||
productEntity, err = _i.Repo.Create(productEntity)
|
productEntity, err = _i.Repo.Create(productEntity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
host := _i.Cfg.App.Domain
|
host := _i.Cfg.App.Domain
|
||||||
|
|
||||||
product = mapper.ProductsResponseMapper(productEntity, host)
|
product = mapper.ProductsResponseMapper(productEntity, host)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ enable = true
|
||||||
|
|
||||||
[middleware.limiter]
|
[middleware.limiter]
|
||||||
enable = false
|
enable = false
|
||||||
max = 20
|
max = 500
|
||||||
expiration_seconds = 60
|
expiration_seconds = 60
|
||||||
|
|
||||||
[middleware.csrf]
|
[middleware.csrf]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue