This commit is contained in:
2026-09-14 08:52:58 +02:00
10 changed files with 825 additions and 99 deletions
+2 -2
View File
@@ -4,8 +4,8 @@
# password=<databaseUserPassword> dbname=<databaseName>
[database]
connection_string = "host=192.168.178.50 port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable"
## connection_string = "host=localhost port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable"
##connection_string = "host=192.168.178.50 port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable"
connection_string = "host=localhost port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable"
driver_name = "postgres"
################################################################
@@ -0,0 +1,52 @@
package repositories
import (
"database/sql"
"xcpq_editor/internal/models"
)
type Import_Repository struct {
db *sql.DB
vr *Value_Repository
pt *Property_Type_Repository
ptg *Property_Types_Group_Repository
pr *Property_Repository
}
func NewImport_Repository(db *sql.DB, vr *Value_Repository, pt *Property_Type_Repository, ptg *Property_Types_Group_Repository, pr *Property_Repository) *Import_Repository {
return &Import_Repository{
db: db,
vr: vr,
pt: pt,
ptg: ptg,
pr: pr,
}
}
func (r *Import_Repository) ImportPropertyTypesData(newGroup *models.Property_Types_Group, parentGroup *models.Property_Types_Group) error {
// Implement the import logic here
if newGroup.Id == 0 {
/**
* If the root ID is 0, it means the root property types group is not yet persisted.
* Implement the logic to handle this case, e.g., insert the root group into the database.
*/
group, err := r.ptg.CreatePropertyTypesGroup(newGroup, parentGroup)
if err != nil {
return err
}
newGroup.Id = group.Id
for _, childPropertyType := range newGroup.Property_Types {
_, err := r.pt.CreatePropertyType(&childPropertyType, newGroup, &childPropertyType.Property)
if err != nil {
return err
}
}
for _, childGroup := range newGroup.Property_Types_Groups {
err := r.ImportPropertyTypesData(&childGroup, newGroup)
if err != nil {
return err
}
}
}
return nil
}
@@ -0,0 +1,20 @@
package services
import (
"xcpq_editor/internal/models"
"xcpq_editor/internal/repositories"
)
type Import_Service struct {
importRepository *repositories.Import_Repository
}
func NewImport_Service(importRepository *repositories.Import_Repository) *Import_Service {
return &Import_Service{
importRepository: importRepository,
}
}
func (s *Import_Service) ImportPropertyTypesData(newGroup *models.Property_Types_Group, parentGroup *models.Property_Types_Group) error {
return s.importRepository.ImportPropertyTypesData(newGroup, parentGroup)
}