finishing products API

This commit is contained in:
2026-08-17 20:12:24 +02:00
parent 989cda7036
commit a72b0fdd4b
7 changed files with 484 additions and 30 deletions
@@ -1,6 +1,7 @@
package controller
import (
"log"
"net/http"
"simplycpq/models"
@@ -141,22 +142,25 @@ func (pgc *ProductGroupController) DeletePropertyFromProductGroupId(c *gin.Conte
}
func (pgc *ProductGroupController) CreatePropertyToProductGroupId(c *gin.Context) {
var property models.Property
if err := c.ShouldBindJSON(&property); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
productGroupId, err := strconv.Atoi(c.Param("productGroupId"))
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid product group ID"})
return
}
property2, err := pgc.productGroupService.CreatePropertyToProductGroupId(productGroupId, &property)
log.Println("ProductGroupId:", productGroupId)
log.Println("PropertyTypeId:", c.Param("propertyTypeId"))
propertyTypeId, err := strconv.Atoi(c.Param("propertyTypeId"))
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid property type ID"})
return
}
property, err := pgc.valueService.CreatePropertyFromPropertyTypeId(propertyTypeId, productGroupId, 0)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "Property created", "data": property2})
c.JSON(http.StatusOK, gin.H{"message": "Property created", "data": property})
}