This commit is contained in:
2026-08-16 19:49:34 +02:00
parent 5060fe5a2e
commit 989cda7036
4 changed files with 19 additions and 19 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS values (
); );
-- Property Table -- Property Table
CREATE TABLE IF NOT EXISTS propertys ( CREATE TABLE IF NOT EXISTS properties (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'), id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT, Label TEXT,
description TEXT, description TEXT,
@@ -34,7 +34,7 @@ func (pgc *ProductGroupController) CreateProductGroup(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusOK, createdProductGroup) c.JSON(http.StatusOK, gin.H{"message": "ProductGroup created", "data": createdProductGroup})
} }
func (pgc *ProductGroupController) UpdateProductGroup(c *gin.Context) { func (pgc *ProductGroupController) UpdateProductGroup(c *gin.Context) {
@@ -48,7 +48,7 @@ func (pgc *ProductGroupController) UpdateProductGroup(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusOK, updatedProductGroup) c.JSON(http.StatusOK, gin.H{"message": "ProductGroup updated", "data": updatedProductGroup})
} }
func (pgc *ProductGroupController) DeleteProductGroup(c *gin.Context) { func (pgc *ProductGroupController) DeleteProductGroup(c *gin.Context) {
@@ -76,7 +76,7 @@ func (pgc *ProductGroupController) GetProductGroup(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusOK, productGroup) c.JSON(http.StatusOK, gin.H{"message": "ProductGroup retrieved", "data": productGroup})
} }
func (pgc *ProductGroupController) GetProductGroupsByParentId(c *gin.Context) { func (pgc *ProductGroupController) GetProductGroupsByParentId(c *gin.Context) {
@@ -90,16 +90,16 @@ func (pgc *ProductGroupController) GetProductGroupsByParentId(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusOK, productGroups) c.JSON(http.StatusOK, gin.H{"message": "ProductGroups retrieved", "data": productGroups})
} }
func (pgc *ProductGroupController) DeleteProductFromProductGroupId(c *gin.Context) { func (pgc *ProductGroupController) DeleteProductFromProductGroupId(c *gin.Context) {
productId, err := strconv.Atoi(c.Param("productId")) productGroupId, err := strconv.Atoi(c.Param("productGroupId"))
if err != nil { if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid product ID"}) c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid product group ID"})
return return
} }
err = pgc.productGroupService.DeleteProductFromProductGroupId(productId) err = pgc.productGroupService.DeleteProductFromProductGroupId(productGroupId)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
@@ -118,7 +118,7 @@ func (pgc *ProductGroupController) GetPropertiesFromProductGroupId(c *gin.Contex
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusOK, properties) c.JSON(http.StatusOK, gin.H{"message": "Properties retrieved", "data": properties})
} }
func (pgc *ProductGroupController) DeletePropertyFromProductGroupId(c *gin.Context) { func (pgc *ProductGroupController) DeletePropertyFromProductGroupId(c *gin.Context) {
@@ -158,5 +158,5 @@ func (pgc *ProductGroupController) CreatePropertyToProductGroupId(c *gin.Context
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
c.JSON(http.StatusOK, property2) c.JSON(http.StatusOK, gin.H{"message": "Property created", "data": property2})
} }
@@ -19,7 +19,7 @@ func NewProductGroupRepository(db *sql.DB, valueRepository *ValueRepository) *Pr
func (r *ProductGroupRepository) CreateProductGroup(productGroup *models.ProductGroup) (*models.ProductGroup, error) { func (r *ProductGroupRepository) CreateProductGroup(productGroup *models.ProductGroup) (*models.ProductGroup, error) {
// Insert the product group into the database // Insert the product group into the database
query := "INSERT INTO product_groups (label, description, parentgroupid) VALUES($1,$2,$3) RETURNING id" query := "INSERT INTO productgroups (label, description, parentgroupid) VALUES($1,$2,$3) RETURNING id"
err := r.db.QueryRow(query, productGroup.Label, productGroup.Description, productGroup.ParentGroupID).Scan(&productGroup.ID) err := r.db.QueryRow(query, productGroup.Label, productGroup.Description, productGroup.ParentGroupID).Scan(&productGroup.ID)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -42,7 +42,7 @@ func (r *ProductGroupRepository) CreateProductGroup(productGroup *models.Product
} }
func (r *ProductGroupRepository) UpdateProductGroup(productGroup *models.ProductGroup) (*models.ProductGroup, error) { func (r *ProductGroupRepository) UpdateProductGroup(productGroup *models.ProductGroup) (*models.ProductGroup, error) {
query := "UPDATE product_groups SET label=$1, description=$2, parentgroupid=$3 WHERE id=$4" query := "UPDATE productgroups SET label=$1, description=$2, parentgroupid=$3 WHERE id=$4"
_, err := r.db.Exec(query, productGroup.Label, productGroup.Description, productGroup.ParentGroupID, productGroup.ID) _, err := r.db.Exec(query, productGroup.Label, productGroup.Description, productGroup.ParentGroupID, productGroup.ID)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -51,7 +51,7 @@ func (r *ProductGroupRepository) UpdateProductGroup(productGroup *models.Product
} }
func (r *ProductGroupRepository) DeleteProductGroup(id int) error { func (r *ProductGroupRepository) DeleteProductGroup(id int) error {
query := "DELETE FROM product_groups WHERE id=$1" query := "DELETE FROM productgroups WHERE id=$1"
_, err := r.db.Exec(query, id) _, err := r.db.Exec(query, id)
if err != nil { if err != nil {
return err return err
@@ -60,7 +60,7 @@ func (r *ProductGroupRepository) DeleteProductGroup(id int) error {
} }
func (r *ProductGroupRepository) GetProductGroup(id int) (*models.ProductGroup, error) { func (r *ProductGroupRepository) GetProductGroup(id int) (*models.ProductGroup, error) {
query := "SELECT id, label, description, parentgroupid FROM product_groups WHERE id=$1" query := "SELECT id, label, description, parentgroupid FROM productgroups WHERE id=$1"
row := r.db.QueryRow(query, id) row := r.db.QueryRow(query, id)
productGroup := &models.ProductGroup{} productGroup := &models.ProductGroup{}
err := row.Scan(&productGroup.ID, &productGroup.Label, &productGroup.Description, &productGroup.ParentGroupID) err := row.Scan(&productGroup.ID, &productGroup.Label, &productGroup.Description, &productGroup.ParentGroupID)
@@ -71,7 +71,7 @@ func (r *ProductGroupRepository) GetProductGroup(id int) (*models.ProductGroup,
} }
func (r *ProductGroupRepository) GetProductGroupsByParentId(parentId int) ([]*models.ProductGroup, error) { func (r *ProductGroupRepository) GetProductGroupsByParentId(parentId int) ([]*models.ProductGroup, error) {
query := "SELECT id, label, description, parentgroupid FROM product_groups WHERE parentgroupid=$1" query := "SELECT id, label, description, parentgroupid FROM productgroups WHERE parentgroupid=$1"
rows, err := r.db.Query(query, parentId) rows, err := r.db.Query(query, parentId)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -169,7 +169,7 @@ func (vr *ValueRepository) GetPropertyTypesByGroupId(groupId int) ([]*models.Pro
func (vr *ValueRepository) CreateValueForPropertyTypeId(propertyTypeId int, value *models.Value) (*models.Value, error) { func (vr *ValueRepository) CreateValueForPropertyTypeId(propertyTypeId int, value *models.Value) (*models.Value, error) {
// Implement the logic to insert the value into the database for the given propertyTypeId // Implement the logic to insert the value into the database for the given propertyTypeId
query := `INSERT INTO values(propertytypeid, label, description) VALUES($1,$2,$3) RETURNING id` query := `INSERT INTO values(propertyid, label, description) VALUES($1,$2,$3) RETURNING id`
err := vr.db.QueryRow(query, propertyTypeId, value.Label, value.Description).Scan(&value.ID) err := vr.db.QueryRow(query, propertyTypeId, value.Label, value.Description).Scan(&value.ID)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -179,7 +179,7 @@ func (vr *ValueRepository) CreateValueForPropertyTypeId(propertyTypeId int, valu
func (vr *ValueRepository) DeleteValueFromPropertyTypeId(propertyTypeId int) error { func (vr *ValueRepository) DeleteValueFromPropertyTypeId(propertyTypeId int) error {
// Implement the logic to delete the value from the database for the given propertyTypeId // Implement the logic to delete the value from the database for the given propertyTypeId
query := `DELETE FROM values WHERE propertytypeid=$1` query := `DELETE FROM values WHERE propertid=$1`
_, err := vr.db.Exec(query, propertyTypeId) _, err := vr.db.Exec(query, propertyTypeId)
if err != nil { if err != nil {
return err return err
@@ -189,7 +189,7 @@ func (vr *ValueRepository) DeleteValueFromPropertyTypeId(propertyTypeId int) err
func (vr *ValueRepository) GetValuesFromPropertyTypeId(propertyTypeId int) ([]*models.Value, error) { func (vr *ValueRepository) GetValuesFromPropertyTypeId(propertyTypeId int) ([]*models.Value, error) {
// Implement the logic to retrieve the values from the database for the given propertyTypeId // Implement the logic to retrieve the values from the database for the given propertyTypeId
query := `SELECT id, label, description FROM values WHERE propertytypeid=$1` query := `SELECT id, label, description FROM values WHERE propertyid=$1`
rows, err := vr.db.Query(query, propertyTypeId) rows, err := vr.db.Query(query, propertyTypeId)
if err != nil { if err != nil {
return nil, err return nil, err