Tree steht
This commit is contained in:
@@ -138,8 +138,6 @@ func (pr *Property_Repository) GetPropertyByPropertyType(property_type *models.P
|
||||
FROM properties.properties
|
||||
WHERE property_type_id = $1`
|
||||
property := &models.Property{}
|
||||
property.Property_Type = property_type
|
||||
log.Printf("Repository: Retrieving property for property type with ID %d", property_type.Id)
|
||||
|
||||
var parent_property_id int
|
||||
var products_groups_id int
|
||||
@@ -148,12 +146,11 @@ func (pr *Property_Repository) GetPropertyByPropertyType(property_type *models.P
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("Repository: Retrieved property with ID %d for property type with ID %d", property.Id, property_type.Id)
|
||||
|
||||
if parent_property_id != 0 {
|
||||
parent_property, err := pr.GetPropertyById(parent_property_id)
|
||||
if err == nil {
|
||||
property.Parent_Property = parent_property
|
||||
log.Printf("Repository: Appending parent property with ID %d to property with ID %d", parent_property.Id, property.Id)
|
||||
}
|
||||
} else {
|
||||
property.Parent_Property = nil
|
||||
|
||||
+68
-9
@@ -45,7 +45,40 @@ func (ptrg *Property_Types_Group_Repository) GetPropertyTypesGroupById(id int) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("Repository: Retrieved property types group with ID %d", id)
|
||||
// get all property
|
||||
queryProperties := "SELECT id FROM properties.property_types WHERE property_types_groups_id = $1"
|
||||
rowsProperties, err := ptrg.db.Query(queryProperties, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rowsProperties.Close()
|
||||
|
||||
for rowsProperties.Next() {
|
||||
id := 0
|
||||
err := rowsProperties.Scan(&id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("Retrieved property type with ID %d for property types group with ID %d", id, property_types_group.Id)
|
||||
property, err := ptrg.property_Type_Repository.GetPropertyTypeById(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("Appending property type with ID %d to property types group with ID %d", property.Id, property_types_group.Id)
|
||||
property_types_group.Property_Types = append(property_types_group.Property_Types, *property)
|
||||
}
|
||||
|
||||
return property_types_group, nil
|
||||
}
|
||||
|
||||
func (ptrg *Property_Types_Group_Repository) GetPropertyTypesGroupWithDirectChildsById(id int) (*models.Property_Types_Group, error) {
|
||||
// Implement the logic to retrieve a property types group by its ID from the database
|
||||
property_types_group, err := ptrg.GetPropertyTypesGroupById(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// get all childs
|
||||
queryChilds := "SELECT id FROM properties.property_types_groups WHERE parent_property_type_group_id = $1"
|
||||
rows, err := ptrg.db.Query(queryChilds, id)
|
||||
@@ -60,16 +93,44 @@ func (ptrg *Property_Types_Group_Repository) GetPropertyTypesGroupById(id int) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("Repository: Retrieved child property types group with ID %d", id)
|
||||
child, err := ptrg.GetPropertyTypesGroupById(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("Repository: Appending child property types group with ID %d to parent with ID %d", child.Id, property_types_group.Id)
|
||||
property_types_group.Property_Types_Groups = append(property_types_group.Property_Types_Groups, *child)
|
||||
}
|
||||
|
||||
log.Printf("Repository: Retrieved all child property types groups for parent with ID %d", property_types_group.Id)
|
||||
return property_types_group, nil
|
||||
}
|
||||
|
||||
func (ptrg *Property_Types_Group_Repository) GetPropertyTypesGroupDirectChildGroupsById(id int) ([]*models.Property_Types_Group, error) {
|
||||
// get all childs
|
||||
queryChilds := "SELECT id FROM properties.property_types_groups WHERE parent_property_type_group_id = $1"
|
||||
rows, err := ptrg.db.Query(queryChilds, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
property_Types_Groups := []*models.Property_Types_Group{}
|
||||
|
||||
for rows.Next() {
|
||||
id := 0
|
||||
err := rows.Scan(&id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
child, err := ptrg.GetPropertyTypesGroupById(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
property_Types_Groups = append(property_Types_Groups, child)
|
||||
}
|
||||
return property_Types_Groups, nil
|
||||
}
|
||||
|
||||
func (ptrg *Property_Types_Group_Repository) GetPropertyTypesGroupPropertyTypesById(id int) ([]*models.Property_Type, error) {
|
||||
|
||||
// get all property
|
||||
queryProperties := "SELECT id FROM properties.property_types WHERE property_types_groups_id = $1"
|
||||
rowsProperties, err := ptrg.db.Query(queryProperties, id)
|
||||
@@ -78,22 +139,20 @@ func (ptrg *Property_Types_Group_Repository) GetPropertyTypesGroupById(id int) (
|
||||
}
|
||||
defer rowsProperties.Close()
|
||||
|
||||
property_Types := []*models.Property_Type{}
|
||||
for rowsProperties.Next() {
|
||||
id := 0
|
||||
err := rowsProperties.Scan(&id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("Repository: Retrieved property type with ID %d", id)
|
||||
property, err := ptrg.property_Type_Repository.GetPropertyTypeById(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Printf("Repository: Appending property type with ID %d to property types group with ID %d", property.Id, property_types_group.Id)
|
||||
property_types_group.Property_Types = append(property_types_group.Property_Types, *property)
|
||||
property_Types = append(property_Types, property)
|
||||
}
|
||||
log.Printf("Repository: Retrieved all property types for property types group with ID %d", property_types_group.Id)
|
||||
return property_types_group, nil
|
||||
return property_Types, nil
|
||||
}
|
||||
|
||||
func (ptrg *Property_Types_Group_Repository) UpdatePropertyTypesGroup(property_types_group *models.Property_Types_Group) error {
|
||||
|
||||
Reference in New Issue
Block a user