Bugfixing import properties
This commit is contained in:
@@ -4,8 +4,8 @@
|
|||||||
# password=<databaseUserPassword> dbname=<databaseName>
|
# password=<databaseUserPassword> dbname=<databaseName>
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
connection_string = "host=192.168.178.50 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"
|
connection_string = "host=localhost port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable"
|
||||||
driver_name = "postgres"
|
driver_name = "postgres"
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ type Property_Type struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Image_Url string `json:"image_url,omitempty"`
|
Image_Url string `json:"image_url,omitempty"`
|
||||||
Property Property `json:"property,omitempty"`
|
Property Property `json:"property"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package repositories
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"log"
|
|
||||||
"xcpq_editor/internal/models"
|
"xcpq_editor/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,17 +34,14 @@ func (r *Import_Repository) ImportPropertyTypesData(newGroup *models.Property_Ty
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Println("Created new property types group with ID:", group.Id)
|
|
||||||
newGroup.Id = group.Id
|
newGroup.Id = group.Id
|
||||||
for _, childPropertyType := range newGroup.Property_Types {
|
for _, childPropertyType := range newGroup.Property_Types {
|
||||||
log.Println("Creating new property type with ID:", childPropertyType.Id)
|
|
||||||
_, err := r.pt.CreatePropertyType(&childPropertyType, newGroup, &childPropertyType.Property)
|
_, err := r.pt.CreatePropertyType(&childPropertyType, newGroup, &childPropertyType.Property)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, childGroup := range newGroup.Property_Types_Groups {
|
for _, childGroup := range newGroup.Property_Types_Groups {
|
||||||
log.Println("Importing child property types group with ID:", childGroup.Id)
|
|
||||||
err := r.ImportPropertyTypesData(&childGroup, newGroup)
|
err := r.ImportPropertyTypesData(&childGroup, newGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -65,6 +65,14 @@ func (pr *Property_Repository) CreateProperty(
|
|||||||
product.Properties = append(product.Properties, *property)
|
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
|
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) {
|
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
|
// 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)
|
err := vr.db.QueryRow(query, propertyId, value.Value, value.Image_Url).Scan(&value.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
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
|
// 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)
|
_, err := vr.db.Exec(query, valueId, propertyId)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -53,14 +53,14 @@ func (vr *Value_Repository) GetValue(id int) (*models.Value, error) {
|
|||||||
|
|
||||||
func (vr *Value_Repository) DeleteValuesFromPropertyId(propertyId int) error {
|
func (vr *Value_Repository) DeleteValuesFromPropertyId(propertyId int) error {
|
||||||
// Implement the logic to delete all values from the database for the given propertyId
|
// 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)
|
_, err := vr.db.Exec(query, propertyId)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vr *Value_Repository) GetValuesFromPropertyId(propertyId int) ([]*models.Value, error) {
|
func (vr *Value_Repository) GetValuesFromPropertyId(propertyId int) ([]*models.Value, error) {
|
||||||
// Implement the logic to retrieve all values from the database for the given propertyId
|
// 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)
|
rows, err := vr.db.Query(query, propertyId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user