Propertytypegroups-Tree

This commit is contained in:
2026-09-15 19:27:04 +02:00
parent 33acfb0bfc
commit dcb6295091
12 changed files with 220 additions and 20 deletions
@@ -0,0 +1,59 @@
package handlers
import (
"html/template"
"log"
"net/http"
"xcpq_editor/internal/services"
"github.com/gin-gonic/gin"
)
type PropertyTypesHandler struct {
propertyTypeService *services.PropertyTypeService
}
func NewPropertyTypesHandler(propertyTypeService *services.PropertyTypeService) *PropertyTypesHandler {
return &PropertyTypesHandler{
propertyTypeService: propertyTypeService,
}
}
func (h *PropertyTypesHandler) GetRootPropertyTypesGroups(ctx *gin.Context) {
rootGroups, err := h.propertyTypeService.GetRootPropertyTypesGroups()
log.Printf("Handler retrieved %d root property types groups", len(rootGroups))
if rootGroups == nil {
ctx.JSON(http.StatusNotFound, gin.H{"error": "No root property types groups found"})
return
}
// If there was an error but rootGroups is not nil, we still want to return the data
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
log.Printf("Loading template for %d root property types groups", len(rootGroups))
// template for handling the response can be added here if needed
tmpl, err := template.ParseFiles(
"../templates/partials/ptg_treeNode.html",
)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
log.Printf("Template parsed successfully")
// execute template
log.Printf("Executing template with root property types groups")
err = tmpl.Execute(ctx.Writer, rootGroups)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
log.Printf("Template executed successfully")
ctx.JSON(http.StatusOK, rootGroups)
}