Bugfixing import properties
This commit is contained in:
@@ -5,5 +5,5 @@ type Property_Type struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Image_Url string `json:"image_url,omitempty"`
|
||||
Property Property `json:"property,omitempty"`
|
||||
Property Property `json:"property"`
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package repositories
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"xcpq_editor/internal/models"
|
||||
)
|
||||
|
||||
@@ -35,17 +34,14 @@ func (r *Import_Repository) ImportPropertyTypesData(newGroup *models.Property_Ty
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Println("Created new property types group with ID:", group.Id)
|
||||
newGroup.Id = group.Id
|
||||
for _, childPropertyType := range newGroup.Property_Types {
|
||||
log.Println("Creating new property type with ID:", childPropertyType.Id)
|
||||
_, err := r.pt.CreatePropertyType(&childPropertyType, newGroup, &childPropertyType.Property)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, childGroup := range newGroup.Property_Types_Groups {
|
||||
log.Println("Importing child property types group with ID:", childGroup.Id)
|
||||
err := r.ImportPropertyTypesData(&childGroup, newGroup)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -65,6 +65,14 @@ func (pr *Property_Repository) CreateProperty(
|
||||
product.Properties = append(product.Properties, *property)
|
||||
}
|
||||
|
||||
for _, value := range property.Values {
|
||||
v, err := pr.vr.CreateValueForPropertyId(property.Id, &value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
value = *v
|
||||
}
|
||||
|
||||
return property, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ func NewValueRepository(db *sql.DB) *Value_Repository {
|
||||
|
||||
func (vr *Value_Repository) CreateValueForPropertyId(propertyId int, value *models.Value) (*models.Value, error) {
|
||||
// Implement the logic to create a new value for the given propertyId in the database
|
||||
query := `INSERT INTO properties.values (propertyid, value, image_url) VALUES ($1, $2, $3) RETURNING id`
|
||||
query := `INSERT INTO properties.values (properties_id, value, image_url) VALUES ($1, $2, $3) RETURNING id`
|
||||
err := vr.db.QueryRow(query, propertyId, value.Value, value.Image_Url).Scan(&value.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -27,7 +27,7 @@ func (vr *Value_Repository) CreateValueForPropertyId(propertyId int, value *mode
|
||||
|
||||
func (vr *Value_Repository) DeleteValueFromPropertyId(valueId int, propertyId int) error {
|
||||
// Implement the logic to delete the value from the database for the given valueId and propertyId
|
||||
query := `DELETE FROM properties.values WHERE id=$1 AND propertyid=$2`
|
||||
query := `DELETE FROM properties.values WHERE id=$1 AND properties_id=$2`
|
||||
_, err := vr.db.Exec(query, valueId, propertyId)
|
||||
return err
|
||||
}
|
||||
@@ -53,14 +53,14 @@ func (vr *Value_Repository) GetValue(id int) (*models.Value, error) {
|
||||
|
||||
func (vr *Value_Repository) DeleteValuesFromPropertyId(propertyId int) error {
|
||||
// Implement the logic to delete all values from the database for the given propertyId
|
||||
query := `DELETE FROM properties.values WHERE propertyid=$1`
|
||||
query := `DELETE FROM properties.values WHERE properties_id=$1`
|
||||
_, err := vr.db.Exec(query, propertyId)
|
||||
return err
|
||||
}
|
||||
|
||||
func (vr *Value_Repository) GetValuesFromPropertyId(propertyId int) ([]*models.Value, error) {
|
||||
// Implement the logic to retrieve all values from the database for the given propertyId
|
||||
query := `SELECT id, value, image_url FROM properties.values WHERE propertyid=$1`
|
||||
query := `SELECT id, value, image_url FROM properties.values WHERE properties_id=$1`
|
||||
rows, err := vr.db.Query(query, propertyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user