Tree steht
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"xcpq_editor/internal/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -21,7 +21,6 @@ func NewPropertyTypesHandler(propertyTypeService *services.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"})
|
||||
@@ -34,28 +33,35 @@ func (h *PropertyTypesHandler) GetRootPropertyTypesGroups(ctx *gin.Context) {
|
||||
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",
|
||||
)
|
||||
// execute template
|
||||
log.Printf("Rendering root property types groups template with data")
|
||||
ctx.HTML(http.StatusOK, "ptg_treeNode", rootGroups)
|
||||
|
||||
log.Printf("Rendered root property types groups template successfully")
|
||||
}
|
||||
|
||||
func (h *PropertyTypesHandler) GetPropertyTypesGroupDirectChildsById(ctx *gin.Context) {
|
||||
idParam := ctx.Param("id")
|
||||
id, err := strconv.Atoi(idParam)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid ID"})
|
||||
return
|
||||
}
|
||||
|
||||
propertyTypesGroup, err := h.propertyTypeService.GetPropertyTypesGroupWithDirectChildsById(id)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing template: %v", err)
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Template parsed successfully")
|
||||
if propertyTypesGroup == nil {
|
||||
ctx.JSON(http.StatusNotFound, gin.H{"error": "Property types group not found"})
|
||||
return
|
||||
}
|
||||
log.Printf("Rendering direct child property types groups template for property types group with ID %d", id)
|
||||
log.Printf("Direct child property types groups for property types group with ID %d: %v", id, propertyTypesGroup.Property_Types_Groups)
|
||||
log.Printf("Direct child property types groups for property types with ID %d: %v", id, propertyTypesGroup.Property_Types)
|
||||
|
||||
// execute template
|
||||
log.Printf("Executing template with root property types groups")
|
||||
err = tmpl.Execute(ctx.Writer, rootGroups)
|
||||
if err != nil {
|
||||
log.Printf("Error executing template: %v", err)
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
log.Printf("Template executed successfully")
|
||||
ctx.JSON(http.StatusOK, rootGroups)
|
||||
ctx.HTML(http.StatusOK, "ptg_treeNode", propertyTypesGroup.Property_Types_Groups)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user