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})
|
||||
}
|
||||
|
||||
@@ -244,18 +244,24 @@ func (vc *ValueController) GetValuesFromPropertyId(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (vc *ValueController) DeleteValueFromPropertyId(c *gin.Context) {
|
||||
valueId := c.Param("valueId")
|
||||
propertyId := c.Param("propertyId")
|
||||
valueIdInt, err := strconv.Atoi(valueId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid value id"})
|
||||
return
|
||||
}
|
||||
propertyIdInt, err := strconv.Atoi(propertyId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property id"})
|
||||
return
|
||||
}
|
||||
err = vc.valueService.DeleteValueFromPropertyId(propertyIdInt)
|
||||
err = vc.valueService.DeleteValueFromPropertyId(valueIdInt, propertyIdInt)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Value deleted from Property", "propertyId": propertyIdInt})
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Value deleted from Property", "valueId": valueIdInt, "propertyId": propertyIdInt})
|
||||
}
|
||||
|
||||
func (vc *ValueController) GetValue(c *gin.Context) {
|
||||
@@ -272,3 +278,62 @@ func (vc *ValueController) GetValue(c *gin.Context) {
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Value retrieved", "id": idInt, "data": value})
|
||||
}
|
||||
|
||||
func (vc *ValueController) CreateTerminalPropertyForProductGroupId(c *gin.Context) {
|
||||
productGroupId := c.Param("productGroupId")
|
||||
propertyTypeId := c.Param("propertyTypeId")
|
||||
value := c.Param("value")
|
||||
productGroupIdInt, err := strconv.Atoi(productGroupId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid product group id"})
|
||||
return
|
||||
}
|
||||
propertyTypeIdInt, err := strconv.Atoi(propertyTypeId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property type id"})
|
||||
return
|
||||
}
|
||||
err = vc.valueService.CreateTerminalPropertyForProductGroupId(productGroupIdInt, propertyTypeIdInt, value)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Terminal Property created for ProductGroup", "productGroupId": productGroupIdInt, "propertyTypeId": propertyTypeIdInt, "value": value})
|
||||
}
|
||||
|
||||
func (vc *ValueController) CreateTerminalPropertyForProductId(c *gin.Context) {
|
||||
productId := c.Param("productId")
|
||||
propertyTypeId := c.Param("propertyTypeId")
|
||||
value := c.Param("value")
|
||||
productIdInt, err := strconv.Atoi(productId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid product id"})
|
||||
return
|
||||
}
|
||||
propertyTypeIdInt, err := strconv.Atoi(propertyTypeId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property type id"})
|
||||
return
|
||||
}
|
||||
err = vc.valueService.CreateTerminalPropertyForProductId(productIdInt, propertyTypeIdInt, value)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Terminal Property created for Product", "productId": productIdInt, "propertyTypeId": propertyTypeIdInt, "value": value})
|
||||
}
|
||||
|
||||
func (vc *ValueController) SetTerminalValueForProperty(c *gin.Context) {
|
||||
propertyId, err := strconv.Atoi(c.Param("propertyId"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid property ID"})
|
||||
return
|
||||
}
|
||||
value := c.Param("value")
|
||||
err = vc.valueService.SetTerminalValueForProperty(propertyId, value)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Terminal value set for property successfully"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user