HTML
This commit is contained in:
@@ -128,10 +128,10 @@ func (r *PropertyRepository) GetPropertiesByParentPropertyID(pid int) ([]models.
|
||||
return properties, nil
|
||||
}
|
||||
|
||||
func (r *PropertyRepository) GetPropertiesByPropertyTypeID(pid int) ([]models.Property, error) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return models.Property{}, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
@@ -140,7 +140,7 @@ func (r *PropertyRepository) GetPropertiesByPropertyTypeID(pid int) ([]models.Pr
|
||||
var property models.Property
|
||||
err := rows.Scan(&property.Id, &property.Name, &property.Description, &property.ImageURL, &property.ParentPropertyId, &property.PropertyTypeId, &property.ProductGroupId, &property.ProductId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return models.Property{}, err
|
||||
}
|
||||
if cachedProperty, ok := r.cache[property.Id]; ok {
|
||||
properties = append(properties, cachedProperty)
|
||||
@@ -150,7 +150,10 @@ func (r *PropertyRepository) GetPropertiesByPropertyTypeID(pid int) ([]models.Pr
|
||||
}
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
return models.Property{}, err
|
||||
}
|
||||
return properties, nil
|
||||
if len(properties) == 0 {
|
||||
return models.Property{}, nil
|
||||
}
|
||||
return properties[0], nil
|
||||
}
|
||||
|
||||
@@ -33,6 +33,32 @@ func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupByID(id int) (models.P
|
||||
return value, 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var groups []models.PropertyTypeGroup
|
||||
for rows.Next() {
|
||||
var value models.PropertyTypeGroup
|
||||
err := rows.Scan(&value.Id, &value.Name, &value.Description, &value.ParentPropertyTypeGroupId, &value.ImageURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, ok := r.cache[value.Id]; !ok {
|
||||
r.cache[value.Id] = value
|
||||
}
|
||||
|
||||
groups = append(groups, value)
|
||||
}
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return groups, 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)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user