TreeView aufgebaut
This commit is contained in:
@@ -39,7 +39,7 @@ func (r *PropertyRepository) GetPropertyByID(id int) (models.Property, error) {
|
||||
}
|
||||
|
||||
var property models.Property
|
||||
err := r.db.QueryRow("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties WHERE id = ?", id).Scan(&property.Id, &property.Name, &property.Description, &property.ImageURL, &property.ParentPropertyId, &property.PropertyTypeId, &property.ProductGroupId, &property.ProductId)
|
||||
err := r.db.QueryRow("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties.properties WHERE id = $1", id).Scan(&property.Id, &property.Name, &property.Description, &property.ImageURL, &property.ParentPropertyId, &property.PropertyTypeId, &property.ProductGroupId, &property.ProductId)
|
||||
if err != nil {
|
||||
return models.Property{}, err
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func (r *PropertyRepository) GetPropertyByID(id int) (models.Property, error) {
|
||||
}
|
||||
|
||||
func (r *PropertyRepository) GetPropertiesByProductGroupID(pid int) ([]models.Property, error) {
|
||||
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties WHERE product_groups_id = ?", pid)
|
||||
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties.properties WHERE product_groups_id = $1", pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func (r *PropertyRepository) GetPropertiesByProductGroupID(pid int) ([]models.Pr
|
||||
}
|
||||
|
||||
func (r *PropertyRepository) GetPropertiesByProductID(pid int) ([]models.Property, error) {
|
||||
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties WHERE products_id = ?", pid)
|
||||
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties.properties WHERE products_id = $1", pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func (r *PropertyRepository) GetPropertiesByProductID(pid int) ([]models.Propert
|
||||
}
|
||||
|
||||
func (r *PropertyRepository) GetPropertiesByParentPropertyID(pid int) ([]models.Property, error) {
|
||||
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties WHERE parent_property_id = ?", pid)
|
||||
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties.properties WHERE parent_property_id = $1", pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func (r *PropertyRepository) GetPropertiesByParentPropertyID(pid int) ([]models.
|
||||
}
|
||||
|
||||
func (r *PropertyRepository) GetPropertyByPropertyTypeID(pid int) (models.Property, error) {
|
||||
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties WHERE property_type_id = ?", pid)
|
||||
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties.properties WHERE property_type_id = $1", pid)
|
||||
if err != nil {
|
||||
return models.Property{}, err
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package repositories
|
||||
import (
|
||||
"SimplyCPQ2/internal/models"
|
||||
"database/sql"
|
||||
"log"
|
||||
)
|
||||
|
||||
type PropertyTypeGroupRepository struct {
|
||||
@@ -23,18 +24,20 @@ func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupByID(id int) (models.P
|
||||
if value, ok := r.cache[id]; ok {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
log.Println("Fetching property type group by ID:", id)
|
||||
var value models.PropertyTypeGroup
|
||||
err := r.db.QueryRow("SELECT id, name, description, parenz_property_typw_goup_id, image_url FROM property_type_groups WHERE id = ?", id).Scan(&value.Id, &value.Name, &value.Description, &value.ParentPropertyTypeGroupId, &value.ImageURL)
|
||||
err := r.db.QueryRow("SELECT id, name, description, parent_property_type_group_id, image_url FROM properties.property_types_groups WHERE id = $1", id).Scan(&value.Id, &value.Name, &value.Description, &value.ParentPropertyTypeGroupId, &value.ImageURL)
|
||||
if err != nil {
|
||||
log.Println("Error fetching property type group by ID:", err)
|
||||
return models.PropertyTypeGroup{}, err
|
||||
}
|
||||
r.cache[id] = value
|
||||
log.Println("Fetched property type group by ID:", value)
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupsByParentId(parentId int) ([]models.PropertyTypeGroup, error) {
|
||||
rows, err := r.db.Query("SELECT id, name, description, parenz_property_typw_goup_id, image_url FROM property_type_groups WHERE parenz_property_typw_goup_id = ?", parentId)
|
||||
rows, err := r.db.Query("SELECT id, name, description, parent_property_type_group_id, image_url FROM properties.property_types_groups WHERE parent_property_type_group_id = $1", parentId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -59,34 +62,30 @@ func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupsByParentId(parentId i
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func (r *PropertyTypeGroupRepository) GetPropertyTypesByGroupId(gid int) ([]models.PropertyTypeGroup, error) {
|
||||
rows, err := r.db.Query("SELECT id, name, description, parenz_property_typw_goup_id, image_url FROM property_type_groups WHERE parenz_property_typw_goup_id = ?", gid)
|
||||
func (r *PropertyTypeGroupRepository) GetPropertyTypesByGroupId(gid int) ([]models.PropertyType, error) {
|
||||
rows, err := r.db.Query("SELECT id, name, description, property_type_group_id, image_url FROM properties.property_types WHERE property_type_group_id = $1", gid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var groups []models.PropertyTypeGroup
|
||||
var types []models.PropertyType
|
||||
for rows.Next() {
|
||||
var value models.PropertyTypeGroup
|
||||
err := rows.Scan(&value.Id, &value.Name, &value.Description, &value.ParentPropertyTypeGroupId, &value.ImageURL)
|
||||
var value models.PropertyType
|
||||
err := rows.Scan(&value.Id, &value.Name, &value.Description, &value.PropertyTypeGroupId, &value.ImageURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, ok := r.cache[value.Id]; !ok {
|
||||
r.cache[value.Id] = value
|
||||
}
|
||||
|
||||
groups = append(groups, value)
|
||||
types = append(types, value)
|
||||
}
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return groups, nil
|
||||
return types, nil
|
||||
}
|
||||
|
||||
func (r *PropertyTypeGroupRepository) CreatePropertyTypeGroup(value models.PropertyTypeGroup) (models.PropertyTypeGroup, error) {
|
||||
result, err := r.db.Exec("INSERT INTO property_type_groups (name) VALUES (?)", value.Name)
|
||||
result, err := r.db.Exec("INSERT INTO properties.property_types_groups (name, description, parent_property_type_group_id, image_url) VALUES ($1, $2, $3, $4)", value.Name, value.Description, value.ParentPropertyTypeGroupId, value.ImageURL)
|
||||
if err != nil {
|
||||
return models.PropertyTypeGroup{}, err
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func (r *PropertyTypeRepository) GetPropertyTypeByID(id int) (models.PropertyTyp
|
||||
return propertyType, nil
|
||||
}
|
||||
var propertyType models.PropertyType
|
||||
err := r.db.QueryRow("SELECT id, name, description, image_url, property_types_groups_id FROM property_types WHERE id = ?", id).Scan(&propertyType.Id, &propertyType.Name, &propertyType.Description, &propertyType.ImageURL, &propertyType.PropertyTypesGroupsId)
|
||||
err := r.db.QueryRow("SELECT id, name, description, image_url, property_type_group_id FROM properties.property_types WHERE id = $1", id).Scan(&propertyType.Id, &propertyType.Name, &propertyType.Description, &propertyType.ImageURL, &propertyType.PropertyTypeGroupId)
|
||||
if err != nil {
|
||||
return models.PropertyType{}, err
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func (r *PropertyTypeRepository) GetPropertyTypeByID(id int) (models.PropertyTyp
|
||||
}
|
||||
|
||||
func (r *PropertyTypeRepository) GetPropertyTypesByGroupID(pid int) ([]models.PropertyType, error) {
|
||||
rows, err := r.db.Query("SELECT id, name, description, image_url, property_types_groups_id FROM property_types WHERE property_types_groups_id = ?", pid)
|
||||
rows, err := r.db.Query("SELECT id, name, description, image_url, property_type_group_id FROM properties.property_types WHERE property_type_group_id = $1", pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func (r *PropertyTypeRepository) GetPropertyTypesByGroupID(pid int) ([]models.Pr
|
||||
var propertyTypes []models.PropertyType
|
||||
for rows.Next() {
|
||||
var propertyType models.PropertyType
|
||||
err := rows.Scan(&propertyType.Id, &propertyType.Name, &propertyType.Description, &propertyType.ImageURL, &propertyType.PropertyTypesGroupsId)
|
||||
err := rows.Scan(&propertyType.Id, &propertyType.Name, &propertyType.Description, &propertyType.ImageURL, &propertyType.PropertyTypeGroupId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (r *PropertyTypeRepository) GetPropertyTypesByGroupID(pid int) ([]models.Pr
|
||||
}
|
||||
|
||||
func (r *PropertyTypeRepository) createPropertyType(propertyType models.PropertyType) (models.PropertyType, error) {
|
||||
result, err := r.db.Exec("INSERT INTO property_types (name, description, image_url, property_types_groups_id) VALUES (?, ?, ?, ?)", propertyType.Name, propertyType.Description, propertyType.ImageURL, propertyType.PropertyTypesGroupsId)
|
||||
result, err := r.db.Exec("INSERT INTO properties.property_types (name, description, image_url, property_type_group_id) VALUES ($1, $2, $3, $4)", propertyType.Name, propertyType.Description, propertyType.ImageURL, propertyType.PropertyTypeGroupId)
|
||||
if err != nil {
|
||||
return models.PropertyType{}, err
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func (r *ValueRepository) GetValueByID(id int) (models.Value, error) {
|
||||
}
|
||||
|
||||
var value models.Value
|
||||
err := r.db.QueryRow("SELECT id, value, image_url FROM values WHERE id = ?", id).Scan(&value.Id, &value.Value, &value.ImageURL)
|
||||
err := r.db.QueryRow("SELECT id, value, image_url FROM properties.values WHERE id = ?", id).Scan(&value.Id, &value.Value, &value.ImageURL)
|
||||
if err != nil {
|
||||
return models.Value{}, err
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func (r *ValueRepository) GetValueByID(id int) (models.Value, error) {
|
||||
}
|
||||
|
||||
func (r *ValueRepository) GetValuesByPropertyId(pid int) ([]models.Value, error) {
|
||||
rows, err := r.db.Query("SELECT id, value, image_url, properties_id FROM values WHERE properties_id = ?", pid)
|
||||
rows, err := r.db.Query("SELECT id, value, image_url, properties_id FROM properties.values WHERE properties_id = ?", pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func (r *ValueRepository) GetValuesByPropertyId(pid int) ([]models.Value, error)
|
||||
}
|
||||
|
||||
func (r *ValueRepository) CreateValue(value models.Value) (models.Value, error) {
|
||||
result, err := r.db.Exec("INSERT INTO values (value, image_url, properties_id) VALUES (?, ?, ?)", value.Value, value.ImageURL, value.PropertiesId)
|
||||
result, err := r.db.Exec("INSERT INTO properties.values (value, image_url, properties_id) VALUES (?, ?, ?)", value.Value, value.ImageURL, value.PropertiesId)
|
||||
if err != nil {
|
||||
return models.Value{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user