diff --git a/xcpq/buildtime/xcpq_editor/cmd/config.toml b/xcpq/buildtime/xcpq_editor/cmd/config.toml index 870a09505..697182581 100644 --- a/xcpq/buildtime/xcpq_editor/cmd/config.toml +++ b/xcpq/buildtime/xcpq_editor/cmd/config.toml @@ -4,8 +4,8 @@ # password= dbname= [database] -connection_string = "host=192.168.178.50 port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable" -##connection_string = "host=localhost port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable" +##connection_string = "host=192.168.178.50 port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable" +connection_string = "host=localhost port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable" driver_name = "postgres" ################################################################ diff --git a/xcpq/buildtime/xcpq_editor/internal/models/property_type.go b/xcpq/buildtime/xcpq_editor/internal/models/property_type.go index 60a0d2dfd..1cbbba1da 100644 --- a/xcpq/buildtime/xcpq_editor/internal/models/property_type.go +++ b/xcpq/buildtime/xcpq_editor/internal/models/property_type.go @@ -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"` } diff --git a/xcpq/buildtime/xcpq_editor/internal/repositories/import_repository.go b/xcpq/buildtime/xcpq_editor/internal/repositories/import_repository.go index 424c3a1be..1701dbd7d 100644 --- a/xcpq/buildtime/xcpq_editor/internal/repositories/import_repository.go +++ b/xcpq/buildtime/xcpq_editor/internal/repositories/import_repository.go @@ -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 diff --git a/xcpq/buildtime/xcpq_editor/internal/repositories/property_repository.go b/xcpq/buildtime/xcpq_editor/internal/repositories/property_repository.go index 4bea50887..813f053d9 100644 --- a/xcpq/buildtime/xcpq_editor/internal/repositories/property_repository.go +++ b/xcpq/buildtime/xcpq_editor/internal/repositories/property_repository.go @@ -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 } diff --git a/xcpq/buildtime/xcpq_editor/internal/repositories/value_repository.go b/xcpq/buildtime/xcpq_editor/internal/repositories/value_repository.go index 6c88f7df6..7ff6f6b89 100644 --- a/xcpq/buildtime/xcpq_editor/internal/repositories/value_repository.go +++ b/xcpq/buildtime/xcpq_editor/internal/repositories/value_repository.go @@ -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