Mhamdans17 commited on
Commit ·
44f1ca9
1
Parent(s): 59cc420
feat: auto-generate unique SKU when blank during product creation to match Python FastAPI schema validation behavior
Browse files
controllers/product_controller.go
CHANGED
|
@@ -12,6 +12,7 @@ import (
|
|
| 12 |
|
| 13 |
"github.com/gin-gonic/gin"
|
| 14 |
"gorm.io/gorm"
|
|
|
|
| 15 |
)
|
| 16 |
|
| 17 |
// DTOs untuk Kategori & Produk
|
|
@@ -374,8 +375,9 @@ func CreateProduct(c *gin.Context) {
|
|
| 374 |
return
|
| 375 |
}
|
| 376 |
|
| 377 |
-
if req.SKU
|
| 378 |
-
|
|
|
|
| 379 |
}
|
| 380 |
|
| 381 |
// Verifikasi SKU jika diisi
|
|
|
|
| 12 |
|
| 13 |
"github.com/gin-gonic/gin"
|
| 14 |
"gorm.io/gorm"
|
| 15 |
+
"math/rand"
|
| 16 |
)
|
| 17 |
|
| 18 |
// DTOs untuk Kategori & Produk
|
|
|
|
| 375 |
return
|
| 376 |
}
|
| 377 |
|
| 378 |
+
if req.SKU == nil || *req.SKU == "" {
|
| 379 |
+
generated := fmt.Sprintf("SKU-%04X%04X", rand.Intn(65536), rand.Intn(65536))
|
| 380 |
+
req.SKU = &generated
|
| 381 |
}
|
| 382 |
|
| 383 |
// Verifikasi SKU jika diisi
|