Bugfixes
This commit is contained in:
@@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS values (
|
||||
);
|
||||
|
||||
-- Property Table
|
||||
CREATE TABLE IF NOT EXISTS propertys (
|
||||
CREATE TABLE IF NOT EXISTS properties (
|
||||
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
|
||||
Label TEXT,
|
||||
description TEXT,
|
||||
|
||||
@@ -34,7 +34,7 @@ func (pgc *ProductGroupController) CreateProductGroup(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, createdProductGroup)
|
||||
c.JSON(http.StatusOK, gin.H{"message": "ProductGroup created", "data": createdProductGroup})
|
||||
}
|
||||
|
||||
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()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, updatedProductGroup)
|
||||
c.JSON(http.StatusOK, gin.H{"message": "ProductGroup updated", "data": updatedProductGroup})
|
||||
}
|
||||
|
||||
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()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, productGroup)
|
||||
c.JSON(http.StatusOK, gin.H{"message": "ProductGroup retrieved", "data": productGroup})
|
||||
}
|
||||
|
||||
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()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, productGroups)
|
||||
c.JSON(http.StatusOK, gin.H{"message": "ProductGroups retrieved", "data": productGroups})
|
||||
}
|
||||
|
||||
func (pgc *ProductGroupController) DeleteProductFromProductGroupId(c *gin.Context) {
|
||||
productId, err := strconv.Atoi(c.Param("productId"))
|
||||
productGroupId, err := strconv.Atoi(c.Param("productGroupId"))
|
||||
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
|
||||
}
|
||||
err = pgc.productGroupService.DeleteProductFromProductGroupId(productId)
|
||||
err = pgc.productGroupService.DeleteProductFromProductGroupId(productGroupId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -118,7 +118,7 @@ func (pgc *ProductGroupController) GetPropertiesFromProductGroupId(c *gin.Contex
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, properties)
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Properties retrieved", "data": properties})
|
||||
}
|
||||
|
||||
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()})
|
||||
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) {
|
||||
// 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -42,7 +42,7 @@ func (r *ProductGroupRepository) CreateProductGroup(productGroup *models.Product
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -51,7 +51,7 @@ func (r *ProductGroupRepository) UpdateProductGroup(productGroup *models.Product
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -60,7 +60,7 @@ func (r *ProductGroupRepository) DeleteProductGroup(id int) 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)
|
||||
productGroup := &models.ProductGroup{}
|
||||
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) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -149,4 +149,4 @@ func (r *ProductGroupRepository) CreatePropertyFromProductGroup(productGroupId i
|
||||
}
|
||||
}
|
||||
return property, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ func (vr *ValueRepository) GetPropertyTypesByGroupId(groupId int) ([]*models.Pro
|
||||
|
||||
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
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -179,7 +179,7 @@ func (vr *ValueRepository) CreateValueForPropertyTypeId(propertyTypeId int, valu
|
||||
|
||||
func (vr *ValueRepository) DeleteValueFromPropertyTypeId(propertyTypeId int) error {
|
||||
// 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)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -189,7 +189,7 @@ func (vr *ValueRepository) DeleteValueFromPropertyTypeId(propertyTypeId int) err
|
||||
|
||||
func (vr *ValueRepository) GetValuesFromPropertyTypeId(propertyTypeId int) ([]*models.Value, error) {
|
||||
// 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user