finishing products API
This commit is contained in:
@@ -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})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user