diff --git a/xcpq/buildtime/xcpq_editor/internal/models/product.go b/xcpq/buildtime/xcpq_editor/internal/models/product.go index 34cc22800..279260d31 100644 --- a/xcpq/buildtime/xcpq_editor/internal/models/product.go +++ b/xcpq/buildtime/xcpq_editor/internal/models/product.go @@ -1,7 +1,9 @@ package models type Product struct { - Id int - Name string - Properties []Property + Id int + Name string + description string + image_url string + Properties []Property } diff --git a/xcpq/buildtime/xcpq_editor/internal/models/property.go b/xcpq/buildtime/xcpq_editor/internal/models/property.go index 2e51d9f09..a04c1fc44 100644 --- a/xcpq/buildtime/xcpq_editor/internal/models/property.go +++ b/xcpq/buildtime/xcpq_editor/internal/models/property.go @@ -4,6 +4,7 @@ type Property struct { Id int Name string Description string + image_url string Parent_Property *Property Values []Value } diff --git a/xcpq/buildtime/xcpq_editor/internal/models/property_type.go b/xcpq/buildtime/xcpq_editor/internal/models/property_type.go index 372f0b88c..b44b74098 100644 --- a/xcpq/buildtime/xcpq_editor/internal/models/property_type.go +++ b/xcpq/buildtime/xcpq_editor/internal/models/property_type.go @@ -4,5 +4,6 @@ type Property_Type struct { Id int Name string Description string + image_url string Property Property } diff --git a/xcpq/buildtime/xcpq_editor/internal/models/value.go b/xcpq/buildtime/xcpq_editor/internal/models/value.go index 97568dce0..0d0717ca6 100644 --- a/xcpq/buildtime/xcpq_editor/internal/models/value.go +++ b/xcpq/buildtime/xcpq_editor/internal/models/value.go @@ -1,6 +1,7 @@ package models type Value struct { - Id int - Value string + Id int + Value string + image_url string } diff --git a/xcpq/buildtime/xcpq_editor/internal/repositories/property_repository.go b/xcpq/buildtime/xcpq_editor/internal/repositories/property_repository.go index e3089eee8..10ccaed7f 100644 --- a/xcpq/buildtime/xcpq_editor/internal/repositories/property_repository.go +++ b/xcpq/buildtime/xcpq_editor/internal/repositories/property_repository.go @@ -45,8 +45,8 @@ func (pr *Property_Repository) CreateProperty( parent_property_id = 0 } - query := `INSERT INTO properties (name, description, parent_property_id, property_type_id, product_id) VALUES ($1, $2, $3, $4, $5) RETURNING id` - err := pr.db.QueryRow(query, property.Name, property.Description, parent_property_id, property_type_id, product_id).Scan(&property.Id) + query := `INSERT INTO properties (name, description, parent_property_id, property_type_id, product_id, image_url) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id` + err := pr.db.QueryRow(query, property.Name, property.Description, parent_property_id, property_type_id, product_id, property.image_url).Scan(&property.Id) if err != nil { return nil, err } @@ -70,10 +70,10 @@ func (pr *Property_Repository) CreateProperty( func (pr *Property_Repository) GetPropertyById(id int) (*models.Property, error) { // Implement the logic to retrieve a property by its ID from the database - query := `SELECT id, name, description, parent_property_id FROM properties WHERE id = $1` + query := `SELECT id, name, description, parent_property_id, image_url FROM properties WHERE id = $1` property := &models.Property{} var parent_property_id int - err := pr.db.QueryRow(query, id).Scan(&property.Id, &property.Name, &property.Description, &parent_property_id) + err := pr.db.QueryRow(query, id).Scan(&property.Id, &property.Name, &property.Description, &parent_property_id, &property.image_url) if err != nil { return nil, err } @@ -103,8 +103,8 @@ func (pr *Property_Repository) GetPropertyById(id int) (*models.Property, error) func (pr *Property_Repository) UpdateProperty(property *models.Property) error { // Implement the logic to update an existing property in the database - query := `UPDATE properties SET name=$1, description=$2 WHERE id=$3` - _, err := pr.db.Exec(query, property.Name, property.Description, property.Id) + query := `UPDATE properties SET name=$1, description=$2, image_url=$3 WHERE id=$4` + _, err := pr.db.Exec(query, property.Name, property.Description, property.image_url, property.Id) return err } diff --git a/xcpq/buildtime/xcpq_editor/internal/repositories/property_type_repository.go b/xcpq/buildtime/xcpq_editor/internal/repositories/property_type_repository.go index d4350eaa5..7b6063243 100644 --- a/xcpq/buildtime/xcpq_editor/internal/repositories/property_type_repository.go +++ b/xcpq/buildtime/xcpq_editor/internal/repositories/property_type_repository.go @@ -29,8 +29,8 @@ func (ptr *Property_Type_Repository) CreatePropertyType( } else { property_type_group_id = 0 } - query := `INSERT INTO property_types (name, description, property_type_group_id) VALUES ($1, $2, $3) RETURNING id` - err := ptr.db.QueryRow(query, property_type.Name, property_type.Description, property_type_group_id).Scan(&property_type.Id) + query := `INSERT INTO property_types (name, description, property_type_group_id, image_url) VALUES ($1, $2, $3, $4) RETURNING id` + err := ptr.db.QueryRow(query, property_type.Name, property_type.Description, property_type_group_id, property_type.image_url).Scan(&property_type.Id) if err != nil { return nil, err } @@ -50,9 +50,9 @@ func (ptr *Property_Type_Repository) CreatePropertyType( func (ptr *Property_Type_Repository) GetPropertyTypeById(id int) (*models.Property_Type, error) { // Implement the logic to retrieve a property type by its ID from the database - query := "SELECT id, name, description FROM property_types WHERE id = $1" + query := "SELECT id, name, description, image_url FROM property_types WHERE id = $1" property_type := &models.Property_Type{} - err := ptr.db.QueryRow(query, id).Scan(&property_type.Id, &property_type.Name, &property_type.Description) + err := ptr.db.QueryRow(query, id).Scan(&property_type.Id, &property_type.Name, &property_type.Description, &property_type.image_url) if err != nil { return nil, err } @@ -63,8 +63,8 @@ func (ptr *Property_Type_Repository) GetPropertyTypeById(id int) (*models.Proper func (ptr *Property_Type_Repository) UpdatePropertyType(property_type *models.Property_Type) error { // Implement the logic to update the label/description of an existing property type - query := `UPDATE property_types SET name=$1, description=$2 WHERE id=$3` - _, err := ptr.db.Exec(query, property_type.Name, property_type.Description, property_type.Id) + query := `UPDATE property_types SET name=$1, description=$2, image_url=$3 WHERE id=$4` + _, err := ptr.db.Exec(query, property_type.Name, property_type.Description, property_type.image_url, property_type.Id) return err } diff --git a/xcpq/buildtime/xcpq_editor/internal/repositories/property_types_group_repository.go b/xcpq/buildtime/xcpq_editor/internal/repositories/property_types_group_repository.go new file mode 100644 index 000000000..25ab0f321 --- /dev/null +++ b/xcpq/buildtime/xcpq_editor/internal/repositories/property_types_group_repository.go @@ -0,0 +1,51 @@ +package repositories + +import ( + "database/sql" + "xcpq_editor/internal/models" +) + +type Property_Types_Group_Repository struct { + db *sql.DB +} + +func NewPropertyTypesGroupRepository(db *sql.DB) *Property_Types_Group_Repository { + return &Property_Types_Group_Repository{ + db: db, + } +} + +func (ptrg *Property_Types_Group_Repository) CreatePropertyTypesGroup(property_types_group *models.Property_Types_Group) (*models.Property_Types_Group, error) { + // Implement the logic to create a new property types group in the database + query := `INSERT INTO property_types_groups (name, description, image_url) VALUES ($1, $2, $3) RETURNING id` + err := ptrg.db.QueryRow(query, property_types_group.Name, property_types_group.Description, property_types_group.image_url).Scan(&property_types_group.Id) + if err != nil { + return nil, err + } + return property_types_group, nil +} + +func (ptrg *Property_Types_Group_Repository) GetPropertyTypesGroupById(id int) (*models.Property_Types_Group, error) { + // Implement the logic to retrieve a property types group by its ID from the database + query := "SELECT id, name, description, image_url FROM property_types_groups WHERE id = $1" + property_types_group := &models.Property_Types_Group{} + err := ptrg.db.QueryRow(query, id).Scan(&property_types_group.Id, &property_types_group.Name, &property_types_group.Description, &property_types_group.image_url) + if err != nil { + return nil, err + } + return property_types_group, nil +} + +func (ptrg *Property_Types_Group_Repository) UpdatePropertyTypesGroup(property_types_group *models.Property_Types_Group) error { + // Implement the logic to update the label/description of an existing property types group + query := `UPDATE property_types_groups SET name=$1, description=$2, image_url=$3 WHERE id=$4` + _, err := ptrg.db.Exec(query, property_types_group.Name, property_types_group.Description, property_types_group.image_url, property_types_group.Id) + return err +} + +func (ptrg *Property_Types_Group_Repository) DeletePropertyTypesGroup(id int) error { + // Implement the logic to delete a property types group from the database + query := `DELETE FROM property_types_groups WHERE id=$1` + _, err := ptrg.db.Exec(query, id) + return err +} diff --git a/xcpq/buildtime/xcpq_editor/internal/repositories/value_repository.go b/xcpq/buildtime/xcpq_editor/internal/repositories/value_repository.go index 40ed45bdc..405540399 100644 --- a/xcpq/buildtime/xcpq_editor/internal/repositories/value_repository.go +++ b/xcpq/buildtime/xcpq_editor/internal/repositories/value_repository.go @@ -17,8 +17,8 @@ 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 values (propertyid, value) VALUES ($1, $2) RETURNING id` - err := vr.db.QueryRow(query, propertyId, value.Value).Scan(&value.Id) + query := `INSERT INTO values (propertyid, 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 } @@ -34,17 +34,17 @@ func (vr *Value_Repository) DeleteValueFromPropertyId(valueId int, propertyId in func (vr *Value_Repository) UpdateValue(value *models.Value) error { // Implement the logic to update the value in the database for the given valueId - query := `UPDATE values SET value=$1 WHERE id=$2` - _, err := vr.db.Exec(query, value.Value, value.Id) + query := `UPDATE values SET value=$1, image_url=$2 WHERE id=$3` + _, err := vr.db.Exec(query, value.Value, value.image_url, value.Id) return err } func (vr *Value_Repository) GetValue(id int) (*models.Value, error) { // Implement the logic to retrieve a value by its ID from the database - query := "SELECT id, value FROM values WHERE id = $1" + query := "SELECT id, value, image_url FROM values WHERE id = $1" row := vr.db.QueryRow(query, id) value := &models.Value{} - err := row.Scan(&value.Id, &value.Value) + err := row.Scan(&value.Id, &value.Value, &value.image_url) if err != nil { return nil, err } @@ -60,7 +60,7 @@ func (vr *Value_Repository) DeleteValuesFromPropertyId(propertyId int) 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 - query := `SELECT id, value FROM values WHERE propertyid=$1` + query := `SELECT id, value, image_url FROM values WHERE propertyid=$1` rows, err := vr.db.Query(query, propertyId) if err != nil { return nil, err @@ -70,7 +70,7 @@ func (vr *Value_Repository) GetValuesFromPropertyId(propertyId int) ([]*models.V values := []*models.Value{} for rows.Next() { value := &models.Value{} - err := rows.Scan(&value.ID, &value.Value) + err := rows.Scan(&value.Id, &value.Value, &value.image_url) if err != nil { return nil, err }