From 7ae541aaa965faf849514c026ccb08d8c5b03e2d Mon Sep 17 00:00:00 2001 From: Thomas Sindt Date: Fri, 2 Oct 2026 11:09:35 +0200 Subject: [PATCH] Templates TreeView PTG --- buildtime/cmd/server/httpServer.go | 2 +- .../internal/handler/propertyTypeHandler.go | 26 +++++++++++++-- .../propertyTypeGroupRepository.go | 26 +++++++++++++++ .../internal/services/propertyTypeService.go | 6 +++- buildtime/templates/partials/pt_treenode | 1 + .../templates/partials/ptg_treenode.html | 32 ++++++++++++------- 6 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 buildtime/templates/partials/pt_treenode diff --git a/buildtime/cmd/server/httpServer.go b/buildtime/cmd/server/httpServer.go index a43af65..ce44529 100644 --- a/buildtime/cmd/server/httpServer.go +++ b/buildtime/cmd/server/httpServer.go @@ -38,7 +38,7 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer { // service initialisation: importService := services.NewImportService(importRepository) - propertyTypesService := services.NewPropertyTypeService(propertyTypeRepository, propertyTypeGroupRepository) + propertyTypesService := services.NewPropertyTypeService(propertyRepository, propertyTypeRepository, propertyTypeGroupRepository, valueRepository) // handler initialisation: importHandler := handler.NewImportHandler(importService) diff --git a/buildtime/internal/handler/propertyTypeHandler.go b/buildtime/internal/handler/propertyTypeHandler.go index e072b29..2ba1d9c 100644 --- a/buildtime/internal/handler/propertyTypeHandler.go +++ b/buildtime/internal/handler/propertyTypeHandler.go @@ -1,6 +1,7 @@ package handlers import ( + "SimplyCPQ2/internal/models" "SimplyCPQ2/internal/services" "strconv" @@ -11,6 +12,14 @@ type PropertyTypeHandler struct { propertyTypeService *services.PropertyTypeService } +// Datentypen zum rendern +type PropertyTypeGroupContent struct { + Id int `json:"id"` + Name string `json:"name"` + PropertyTypeGroups []models.PropertyTypeGroup `json:"propertyTypeGroups"` + PropertyTypes []models.PropertyType `json:"propertyTypes"` +} + func NewPropertyTypeHandler(propertyTypeService *services.PropertyTypeService) *PropertyTypeHandler { return &PropertyTypeHandler{ propertyTypeService: propertyTypeService, @@ -31,6 +40,12 @@ func (h *PropertyTypeHandler) GetPropertyTypeGroupContentById(ctx *gin.Context) return } + ptg, err := h.propertyTypeService.GetPropertyTypeGroupByID(id) + if err != nil { + ctx.JSON(500, gin.H{"error": "Failed to get property type group"}) + return + } + // get property type groups by parent ID ptgs, err := h.propertyTypeService.GetPropertyTypeGroupsByParentId(id) if err != nil { @@ -46,10 +61,15 @@ func (h *PropertyTypeHandler) GetPropertyTypeGroupContentById(ctx *gin.Context) } // template for response + content := PropertyTypeGroupContent{ + Id: id, + Name: ptg.Name, + PropertyTypeGroups: ptgs, + PropertyTypes: pts, + } - ctx.JSON(200, gin.H{ - "propertyTypeGroups": ptgs, - "propertyTypes": pts, + ctx.HTML(200, "ptg_treenode.html", gin.H{ + "propertyTypeGroupContent": content, }) // Implement the logic to get property type group content by ID here using idParam diff --git a/buildtime/internal/repositories/propertyTypeGroupRepository.go b/buildtime/internal/repositories/propertyTypeGroupRepository.go index 819cd43..1e36427 100644 --- a/buildtime/internal/repositories/propertyTypeGroupRepository.go +++ b/buildtime/internal/repositories/propertyTypeGroupRepository.go @@ -33,6 +33,32 @@ func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupByID(id int) (models.P return value, nil } +func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupsByParentId(parentId 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 = ?", parentId) + 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) 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 { diff --git a/buildtime/internal/services/propertyTypeService.go b/buildtime/internal/services/propertyTypeService.go index fb4c36c..330f336 100644 --- a/buildtime/internal/services/propertyTypeService.go +++ b/buildtime/internal/services/propertyTypeService.go @@ -25,7 +25,11 @@ func NewPropertyTypeService(propertyRepo *repositories.PropertyRepository, prope // Getter functions func (service *PropertyTypeService) GetPropertyTypeGroupsByParentId(parentId int) ([]models.PropertyTypeGroup, error) { - return service.PropertyTypeGroups_Repository.GetPropertyTypesByGroupId(parentId) + return service.PropertyTypeGroups_Repository.GetPropertyTypeGroupsByParentId(parentId) +} + +func (service *PropertyTypeService) GetPropertyTypeGroupByID(id int) (models.PropertyTypeGroup, error) { + return service.PropertyTypeGroups_Repository.GetPropertyTypeGroupByID(id) } func (service *PropertyTypeService) GetPropertyTypesByGroupId(id int) ([]models.PropertyType, error) { diff --git a/buildtime/templates/partials/pt_treenode b/buildtime/templates/partials/pt_treenode new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/buildtime/templates/partials/pt_treenode @@ -0,0 +1 @@ + diff --git a/buildtime/templates/partials/ptg_treenode.html b/buildtime/templates/partials/ptg_treenode.html index e0a16a4..e0255a9 100644 --- a/buildtime/templates/partials/ptg_treenode.html +++ b/buildtime/templates/partials/ptg_treenode.html @@ -1,18 +1,26 @@ {{define "ptg_treeNode"}} -{{- range .}} - \ No newline at end of file