repository: Add image_url field to property and property_type models

This commit is contained in:
2026-09-01 20:46:41 +02:00
parent 60b056d430
commit 61c6c11142
8 changed files with 81 additions and 25 deletions
@@ -3,5 +3,7 @@ package models
type Product struct {
Id int
Name string
description string
image_url string
Properties []Property
}
@@ -4,6 +4,7 @@ type Property struct {
Id int
Name string
Description string
image_url string
Parent_Property *Property
Values []Value
}
@@ -4,5 +4,6 @@ type Property_Type struct {
Id int
Name string
Description string
image_url string
Property Property
}
@@ -3,4 +3,5 @@ package models
type Value struct {
Id int
Value string
image_url string
}
@@ -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
}
@@ -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
}
@@ -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
}
@@ -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
}