Produkte und Properties im Server
This commit is contained in:
@@ -267,6 +267,48 @@ func (vr *ValueRepository) GetValue(id int) (*models.Value, error) {
|
||||
return &value, nil
|
||||
}
|
||||
|
||||
func (vr *ValueRepository) createPropertyFromPropertyType(productGroupId int, productId int, propertyType *models.PropertyType) (*models.Property, error) {
|
||||
query := `INSERT INTO properties (label, description, propertytypeid, productid, productgroupid) VALUES ($1, $2, $3, $4, $5) RETURNING id`
|
||||
var property models.Property
|
||||
err := vr.db.QueryRow(query, propertyType.Label, propertyType.Description, propertyType.ID, productId, productGroupId).Scan(&property.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
property.Label = propertyType.Label
|
||||
property.Description = propertyType.Description
|
||||
property.PropertyTypeID = propertyType.ID
|
||||
property.ProductID = productId
|
||||
property.ProductGroupID = productGroupId
|
||||
|
||||
// Copy values from property type to property
|
||||
err = vr.copyValuesFromPropertyTypeToProperty(propertyType.ID, property.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &property, nil
|
||||
}
|
||||
|
||||
func (vr *ValueRepository) createPropertyFromProperty(productGroupId int, productId int, property *models.Property) (*models.Property, error) {
|
||||
query := `INSERT INTO properties (label, description, propertytypeid, productid, productgroupid) VALUES ($1, $2, $3, $4, $5) RETURNING id`
|
||||
var newProperty models.Property
|
||||
err := vr.db.QueryRow(query, property.Label, property.Description, property.PropertyTypeID, productId, productGroupId).Scan(&newProperty.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
newProperty.Label = property.Label
|
||||
newProperty.Description = property.Description
|
||||
newProperty.PropertyTypeID = property.PropertyTypeID
|
||||
newProperty.ProductID = productId
|
||||
newProperty.ProductGroupID = productGroupId
|
||||
|
||||
// Copy values from property type to property
|
||||
err = vr.copyValuesFromPropertyToProperty(property.ID, newProperty.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &newProperty, nil
|
||||
}
|
||||
|
||||
func (vr *ValueRepository) copyValuesFromPropertyTypeToProperty(propertyTypeId int, propertyId int) error {
|
||||
// Implement the logic to copy values from a property type to a property
|
||||
query := `INSERT INTO values (propertyId, label, description) SELECT $1, label, description FROM values WHERE propertytypeid=$2`
|
||||
|
||||
Reference in New Issue
Block a user