package controller import ( "net/http" "simplycpq/models" "simplycpq/services" "github.com/gin-gonic/gin" ) type ValueController struct { valueService *services.ValueService } func NewValueController(valueService *services.ValueService) *ValueController { return &ValueController{ valueService: valueService, } } func (vc *ValueController) CreatePropertyTypeGroup(c *gin.Context) { var propertyTypeGroup models.PropertyTypeGroup if err := c.ShouldBindJSON(&propertyTypeGroup); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } createdGroup, err2 := vc.valueService.CreatePropertyTypeGroup(&propertyTypeGroup) if err2 != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err2.Error()}) return } c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroup created", "data": createdGroup}) } func (vc *ValueController) UpdatePropertyTypeGroup(c *gin.Context) { var propertyTypeGroup models.PropertyTypeGroup if err := c.ShouldBindJSON(&propertyTypeGroup); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroup updated", "data": propertyTypeGroup}) } func (vc *ValueController) DeletePropertyTypeGroup(c *gin.Context) { id := c.Param("id") c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroup deleted", "id": id}) } func (vc *ValueController) GetPropertyTypeGroup(c *gin.Context) { id := c.Param("id") c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroup retrieved", "id": id}) } func (vc *ValueController) GetPropertyTypeGroupsByParentId(c *gin.Context) { parentId := c.Param("parentId") c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroups retrieved by parent ID", "parentId": parentId}) } func (vc *ValueController) DeletePropertyTypeFromPropertyTypeGroupId(c *gin.Context) { propertyTypeGroupId := c.Param("propertyTypeGroupId") c.JSON(http.StatusOK, gin.H{"message": "PropertyType deleted from PropertyTypeGroup", "propertyTypeGroupId": propertyTypeGroupId}) } func (vc *ValueController) CreatePropertyType(c *gin.Context) { var propertyType models.PropertyType if err := c.ShouldBindJSON(&propertyType); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } c.JSON(http.StatusOK, gin.H{"message": "PropertyType created", "data": propertyType}) } func (vc *ValueController) UpdatePropertyType(c *gin.Context) { var propertyType models.PropertyType if err := c.ShouldBindJSON(&propertyType); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } c.JSON(http.StatusOK, gin.H{"message": "PropertyType updated", "data": propertyType}) } func (vc *ValueController) DeletePropertyType(c *gin.Context) { id := c.Param("id") c.JSON(http.StatusOK, gin.H{"message": "PropertyType deleted", "id": id}) } func (vc *ValueController) GetPropertyType(c *gin.Context) { id := c.Param("id") c.JSON(http.StatusOK, gin.H{"message": "PropertyType retrieved", "id": id}) } func (vc *ValueController) GetPropertyTypesByGroupId(c *gin.Context) { groupId := c.Param("groupId") c.JSON(http.StatusOK, gin.H{"message": "PropertyTypes retrieved by group ID", "groupId": groupId}) } func (vc *ValueController) CreateValueForPropertyTypeId(c *gin.Context) { propertyTypeId := c.Param("propertyTypeId") var value models.Value if err := c.ShouldBindJSON(&value); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } c.JSON(http.StatusOK, gin.H{"message": "Value created for PropertyType", "propertyTypeId": propertyTypeId, "data": value}) } func (vc *ValueController) DeleteValueFromPropertyTypeId(c *gin.Context) { propertyTypeId := c.Param("propertyTypeId") c.JSON(http.StatusOK, gin.H{"message": "Value deleted from PropertyType", "propertyTypeId": propertyTypeId}) } func (vc *ValueController) GetValuesFromPropertyTypeId(c *gin.Context) { propertyTypeId := c.Param("propertyTypeId") c.JSON(http.StatusOK, gin.H{"message": "Values retrieved from PropertyType", "propertyTypeId": propertyTypeId}) } func (vc *ValueController) GetValuesFromPropertyId(c *gin.Context) { propertyId := c.Param("propertyId") c.JSON(http.StatusOK, gin.H{"message": "Values retrieved from Property", "propertyId": propertyId}) } func (vc *ValueController) DeleteValueFromPropertyId(c *gin.Context) { propertyId := c.Param("propertyId") c.JSON(http.StatusOK, gin.H{"message": "Value deleted from Property", "propertyId": propertyId}) } func (vc *ValueController) GetValue(c *gin.Context) { id := c.Param("id") c.JSON(http.StatusOK, gin.H{"message": "Value retrieved", "id": id}) }