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
+67 -2
View File
@@ -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"})
}