Porpertys und Values Server implementiert
This commit is contained in:
@@ -30,7 +30,7 @@ CREATE TABLE IF NOT EXISTS propertyTypes(
|
||||
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
|
||||
Label TEXT,
|
||||
description TEXT,
|
||||
propertyId BIGINT
|
||||
propertyGroupId BIGINT
|
||||
);
|
||||
|
||||
-- PropertyTypeGroupTable
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
"simplycpq/models"
|
||||
"simplycpq/services"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -38,27 +39,69 @@ func (vc *ValueController) UpdatePropertyTypeGroup(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
err := vc.valueService.UpdatePropertyTypeGroup(&propertyTypeGroup)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, 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})
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property type group id"})
|
||||
return
|
||||
}
|
||||
err = vc.valueService.DeletePropertyTypeGroup(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroup deleted", "data": id})
|
||||
}
|
||||
|
||||
func (vc *ValueController) GetPropertyTypeGroup(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroup retrieved", "id": id})
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property type group id"})
|
||||
return
|
||||
}
|
||||
propertyTypeGroup, err := vc.valueService.GetPropertyTypeGroup(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroup retrieved", "data": propertyTypeGroup})
|
||||
}
|
||||
|
||||
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})
|
||||
parentId, err := strconv.Atoi(c.Param("parentId"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid parent id"})
|
||||
return
|
||||
}
|
||||
propertyTypeGroups, err := vc.valueService.GetPropertyTypeGroupsByParentId(parentId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroups retrieved by parent ID", "parentId": parentId, "data": propertyTypeGroups})
|
||||
}
|
||||
|
||||
func (vc *ValueController) DeletePropertyTypeFromPropertyTypeGroupId(c *gin.Context) {
|
||||
propertyTypeGroupId := c.Param("propertyTypeGroupId")
|
||||
c.JSON(http.StatusOK, gin.H{"message": "PropertyType deleted from PropertyTypeGroup", "propertyTypeGroupId": propertyTypeGroupId})
|
||||
id, err := strconv.Atoi(propertyTypeGroupId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property type group id"})
|
||||
return
|
||||
}
|
||||
err = vc.valueService.DeletePropertyTypeFromPropertyTypeGroupId(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "PropertyType deleted from PropertyTypeGroup", "propertyTypeGroupId": id})
|
||||
}
|
||||
|
||||
func (vc *ValueController) CreatePropertyType(c *gin.Context) {
|
||||
@@ -67,7 +110,13 @@ func (vc *ValueController) CreatePropertyType(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "PropertyType created", "data": propertyType})
|
||||
var propertyType2 *models.PropertyType
|
||||
propertyType2, err := vc.valueService.CreatePropertyType(&propertyType)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "PropertyType created", "data": propertyType2})
|
||||
}
|
||||
|
||||
func (vc *ValueController) UpdatePropertyType(c *gin.Context) {
|
||||
@@ -76,22 +125,57 @@ func (vc *ValueController) UpdatePropertyType(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
err := vc.valueService.UpdatePropertyType(&propertyType)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, 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})
|
||||
idInt, err := strconv.Atoi(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property type id"})
|
||||
return
|
||||
}
|
||||
err = vc.valueService.DeletePropertyType(idInt)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "PropertyType deleted", "id": idInt})
|
||||
}
|
||||
|
||||
func (vc *ValueController) GetPropertyType(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
c.JSON(http.StatusOK, gin.H{"message": "PropertyType retrieved", "id": id})
|
||||
idInt, err := strconv.Atoi(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property type id"})
|
||||
return
|
||||
}
|
||||
propertyType, err := vc.valueService.GetPropertyType(idInt)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "PropertyType retrieved", "data": propertyType})
|
||||
}
|
||||
|
||||
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})
|
||||
groupIdInt, err := strconv.Atoi(groupId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid group id"})
|
||||
return
|
||||
}
|
||||
propertyTypes, err := vc.valueService.GetPropertyTypesByGroupId(groupIdInt)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "PropertyTypes retrieved by group ID", "data": propertyTypes})
|
||||
}
|
||||
|
||||
func (vc *ValueController) CreateValueForPropertyTypeId(c *gin.Context) {
|
||||
@@ -101,30 +185,90 @@ func (vc *ValueController) CreateValueForPropertyTypeId(c *gin.Context) {
|
||||
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})
|
||||
propertyTypeIdInt, err := strconv.Atoi(propertyTypeId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property type id"})
|
||||
return
|
||||
}
|
||||
value2, err := vc.valueService.CreateValueForPropertyTypeId(propertyTypeIdInt, &value)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Value created for PropertyType", "propertyTypeId": propertyTypeIdInt, "data": value2})
|
||||
}
|
||||
|
||||
func (vc *ValueController) DeleteValueFromPropertyTypeId(c *gin.Context) {
|
||||
propertyTypeId := c.Param("propertyTypeId")
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Value deleted from PropertyType", "propertyTypeId": propertyTypeId})
|
||||
propertyTypeIdInt, err := strconv.Atoi(propertyTypeId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property type id"})
|
||||
return
|
||||
}
|
||||
err = vc.valueService.DeleteValueFromPropertyTypeId(propertyTypeIdInt)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Value deleted from PropertyType", "propertyTypeId": propertyTypeIdInt})
|
||||
}
|
||||
|
||||
func (vc *ValueController) GetValuesFromPropertyTypeId(c *gin.Context) {
|
||||
propertyTypeId := c.Param("propertyTypeId")
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Values retrieved from PropertyType", "propertyTypeId": propertyTypeId})
|
||||
propertyTypeIdInt, err := strconv.Atoi(propertyTypeId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property type id"})
|
||||
return
|
||||
}
|
||||
values, err := vc.valueService.GetValuesFromPropertyTypeId(propertyTypeIdInt)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Values retrieved from PropertyType", "propertyTypeId": propertyTypeIdInt, "data": values})
|
||||
}
|
||||
|
||||
func (vc *ValueController) GetValuesFromPropertyId(c *gin.Context) {
|
||||
propertyId := c.Param("propertyId")
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Values retrieved from Property", "propertyId": propertyId})
|
||||
propertyIdInt, err := strconv.Atoi(propertyId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property id"})
|
||||
return
|
||||
}
|
||||
values, err := vc.valueService.GetValuesFromPropertyId(propertyIdInt)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Values retrieved from Property", "propertyId": propertyIdInt, "data": values})
|
||||
}
|
||||
|
||||
func (vc *ValueController) DeleteValueFromPropertyId(c *gin.Context) {
|
||||
propertyId := c.Param("propertyId")
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Value deleted from Property", "propertyId": propertyId})
|
||||
propertyIdInt, err := strconv.Atoi(propertyId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid property id"})
|
||||
return
|
||||
}
|
||||
err = vc.valueService.DeleteValueFromPropertyId(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})
|
||||
}
|
||||
|
||||
func (vc *ValueController) GetValue(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Value retrieved", "id": id})
|
||||
idInt, err := strconv.Atoi(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid value id"})
|
||||
return
|
||||
}
|
||||
value, err := vc.valueService.GetValue(idInt)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Value retrieved", "id": idInt, "data": value})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user