Templates TreeView PTG

This commit is contained in:
2026-10-02 11:09:35 +02:00
parent 679a8a0a3e
commit 7ae541aaa9
6 changed files with 76 additions and 17 deletions
@@ -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