From 81b226a3dad1e2d2fa73bb94b7f5abcc7ddcfe6a Mon Sep 17 00:00:00 2001 From: Thomas Sindt Date: Fri, 21 Aug 2026 13:05:17 +0200 Subject: [PATCH] data import --- .../server/repositories/importRepository.go | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/buildtime/server/repositories/importRepository.go b/buildtime/server/repositories/importRepository.go index 26a64a8e2..77e8c4678 100644 --- a/buildtime/server/repositories/importRepository.go +++ b/buildtime/server/repositories/importRepository.go @@ -24,12 +24,70 @@ func NewImportRepository(db *sql.DB, productGroupRepo *ProductGroupRepository, p func (r *ImportRepository) ImportPropertyTypeGroups(importData []models.ImportPropertyTypeGroup) error { // Implement the logic to import PropertyTypeGroups into the database // This is a placeholder implementation; you need to write the actual logic + for _, data := range importData { + if data.ID != 0 { + // Update existing record + query := "UPDATE propertytypegroups SET label = $1, description = $2 WHERE id = $3" + _, err := r.db.Exec(query, data.Label, data.Description, data.ID) + if err != nil { + return err + } + // + if err := r.ImportPropertyTypes(data.PropertyTypes, data.ID); err != nil { + return err + } + // update subgroups if they exist + if data.SubGroups != nil { + return r.ImportPropertyTypeGroups(data.SubGroups) + } + } else { + // Insert new record + _, err := r.db.Exec("INSERT INTO propertytypegroups (label, description) VALUES ($1, $2)", data.Label, data.Description) + if err != nil { + return err + } + if data.SubGroups != nil { + return r.ImportPropertyTypeGroups(data.SubGroups) + } + } + } return nil } func (r *ImportRepository) ImportProductGroups(importData []models.ImportProductGroup) error { // Implement the logic to import ProductGroups into the database + // Implement the logic to import PropertyTypeGroups into the database // This is a placeholder implementation; you need to write the actual logic + for _, data := range importData { + if data.ID != 0 { + // Update existing record + query := "UPDATE productgroups SET label = $1, description = $2 WHERE id = $3" + _, err := r.db.Exec(query, data.Label, data.Description, data.ID) + if err != nil { + return err + } + // + if err := r.ImportProducts(data.Products); err != nil { + return err + } + // update subgroups if they exist + if data.SubGroups != nil { + return r.ImportProductGroups(data.SubGroups) + } + } else { + // Insert new record + _, err := r.db.Exec("INSERT INTO productgroups (label, description) VALUES ($1, $2)", data.Label, data.Description) + if err != nil { + return err + } + if err := r.ImportProducts(data.Products); err != nil { + return err + } + if data.SubGroups != nil { + return r.ImportProductGroups(data.SubGroups) + } + } + } return nil } @@ -38,3 +96,31 @@ func (r *ImportRepository) ImportProducts(importData []models.ImportProduct) err // This is a placeholder implementation; you need to write the actual logic return nil } + +func (r *ImportRepository) ImportProperties(importData []models.ImportProperty) error { + // Implement the logic to import Properties into the database + // This is a placeholder implementation; you need to write the actual logic + return nil +} + +func (r *ImportRepository) ImportPropertyTypes(importData []models.ImportPropertyType, groupID int) error { + for _, propertyType := range importData { + if propertyType.ID != 0 { + // Update existing PropertyType + query := "UPDATE property_types SET label = $1, description = $2, group_id = $3 WHERE id = $4" + _, err := r.db.Exec(query, propertyType.Label, propertyType.Description, groupID, propertyType.ID) + if err != nil { + return err + } + } else { + // Insert new PropertyType + query := "INSERT INTO property_types (label, description, group_id) VALUES ($1, $2, $3)" + _, err := r.db.Exec(query, propertyType.Label, propertyType.Description, groupID) + if err != nil { + return err + } + } + } + + return nil +}