start implementing dataimport

This commit is contained in:
2026-09-13 09:41:34 +02:00
parent 76db8d4cfe
commit 6ec1fb2816
9 changed files with 401 additions and 0 deletions
@@ -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)
}