TreeView aufgebaut
This commit is contained in:
@@ -3,6 +3,7 @@ package handlers
|
|||||||
import (
|
import (
|
||||||
"SimplyCPQ2/internal/models"
|
"SimplyCPQ2/internal/models"
|
||||||
"SimplyCPQ2/internal/services"
|
"SimplyCPQ2/internal/services"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -40,23 +41,30 @@ func (h *PropertyTypeHandler) GetPropertyTypeGroupContentById(ctx *gin.Context)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ptg, err := h.propertyTypeService.GetPropertyTypeGroupByID(id)
|
var ptg models.PropertyTypeGroup
|
||||||
if err != nil {
|
if id != 0 {
|
||||||
ctx.JSON(500, gin.H{"error": "Failed to get property type group"})
|
ptg, err = h.propertyTypeService.GetPropertyTypeGroupByID(id)
|
||||||
return
|
if err != nil {
|
||||||
|
ctx.JSON(500, gin.H{"error": "Failed to get property type group", "details": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ptg.Name = "Root"
|
||||||
|
ptg.Id = 0
|
||||||
|
ptg.ParentPropertyTypeGroupId = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// get property type groups by parent ID
|
// get property type groups by parent ID
|
||||||
ptgs, err := h.propertyTypeService.GetPropertyTypeGroupsByParentId(id)
|
ptgs, err := h.propertyTypeService.GetPropertyTypeGroupsByParentId(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, gin.H{"error": "Failed to get property type group content"})
|
ctx.JSON(500, gin.H{"error": "Failed to get property type group content", "details": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// get property types by parent ID
|
// get property types by parent ID
|
||||||
pts, err := h.propertyTypeService.GetPropertyTypesByGroupId(id)
|
pts, err := h.propertyTypeService.GetPropertyTypesByGroupId(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.JSON(500, gin.H{"error": "Failed to get property types"})
|
ctx.JSON(500, gin.H{"error": "Failed to get property types", "details": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,9 +76,7 @@ func (h *PropertyTypeHandler) GetPropertyTypeGroupContentById(ctx *gin.Context)
|
|||||||
PropertyTypes: pts,
|
PropertyTypes: pts,
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.HTML(200, "ptg_treenode.html", gin.H{
|
ctx.HTML(http.StatusOK, "ptg_treeNode", content)
|
||||||
"propertyTypeGroupContent": content,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Implement the logic to get property type group content by ID here using idParam
|
// Implement the logic to get property type group content by ID here using idParam
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
type PropertyType struct {
|
type PropertyType struct {
|
||||||
Id int `json:"id,omitempty"`
|
Id int `json:"id,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
ImageURL string `json:"image_url,omitempty"`
|
ImageURL string `json:"image_url,omitempty"`
|
||||||
PropertyTypesGroupsId int `json:"property_types_groups_id,omitempty"`
|
PropertyTypeGroupId int `json:"property_types_groups_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func (r *PropertyRepository) GetPropertyByID(id int) (models.Property, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var property models.Property
|
var property models.Property
|
||||||
err := r.db.QueryRow("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties WHERE id = ?", id).Scan(&property.Id, &property.Name, &property.Description, &property.ImageURL, &property.ParentPropertyId, &property.PropertyTypeId, &property.ProductGroupId, &property.ProductId)
|
err := r.db.QueryRow("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties.properties WHERE id = $1", id).Scan(&property.Id, &property.Name, &property.Description, &property.ImageURL, &property.ParentPropertyId, &property.PropertyTypeId, &property.ProductGroupId, &property.ProductId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.Property{}, err
|
return models.Property{}, err
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ func (r *PropertyRepository) GetPropertyByID(id int) (models.Property, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *PropertyRepository) GetPropertiesByProductGroupID(pid int) ([]models.Property, error) {
|
func (r *PropertyRepository) GetPropertiesByProductGroupID(pid int) ([]models.Property, error) {
|
||||||
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties WHERE product_groups_id = ?", pid)
|
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties.properties WHERE product_groups_id = $1", pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ func (r *PropertyRepository) GetPropertiesByProductGroupID(pid int) ([]models.Pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *PropertyRepository) GetPropertiesByProductID(pid int) ([]models.Property, error) {
|
func (r *PropertyRepository) GetPropertiesByProductID(pid int) ([]models.Property, error) {
|
||||||
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties WHERE products_id = ?", pid)
|
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties.properties WHERE products_id = $1", pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ func (r *PropertyRepository) GetPropertiesByProductID(pid int) ([]models.Propert
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *PropertyRepository) GetPropertiesByParentPropertyID(pid int) ([]models.Property, error) {
|
func (r *PropertyRepository) GetPropertiesByParentPropertyID(pid int) ([]models.Property, error) {
|
||||||
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties WHERE parent_property_id = ?", pid)
|
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties.properties WHERE parent_property_id = $1", pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ func (r *PropertyRepository) GetPropertiesByParentPropertyID(pid int) ([]models.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *PropertyRepository) GetPropertyByPropertyTypeID(pid int) (models.Property, error) {
|
func (r *PropertyRepository) GetPropertyByPropertyTypeID(pid int) (models.Property, error) {
|
||||||
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties WHERE property_type_id = ?", pid)
|
rows, err := r.db.Query("SELECT id, name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id FROM properties.properties WHERE property_type_id = $1", pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.Property{}, err
|
return models.Property{}, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package repositories
|
|||||||
import (
|
import (
|
||||||
"SimplyCPQ2/internal/models"
|
"SimplyCPQ2/internal/models"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PropertyTypeGroupRepository struct {
|
type PropertyTypeGroupRepository struct {
|
||||||
@@ -23,18 +24,20 @@ func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupByID(id int) (models.P
|
|||||||
if value, ok := r.cache[id]; ok {
|
if value, ok := r.cache[id]; ok {
|
||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
log.Println("Fetching property type group by ID:", id)
|
||||||
var value models.PropertyTypeGroup
|
var value models.PropertyTypeGroup
|
||||||
err := r.db.QueryRow("SELECT id, name, description, parenz_property_typw_goup_id, image_url FROM property_type_groups WHERE id = ?", id).Scan(&value.Id, &value.Name, &value.Description, &value.ParentPropertyTypeGroupId, &value.ImageURL)
|
err := r.db.QueryRow("SELECT id, name, description, parent_property_type_group_id, image_url FROM properties.property_types_groups WHERE id = $1", id).Scan(&value.Id, &value.Name, &value.Description, &value.ParentPropertyTypeGroupId, &value.ImageURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println("Error fetching property type group by ID:", err)
|
||||||
return models.PropertyTypeGroup{}, err
|
return models.PropertyTypeGroup{}, err
|
||||||
}
|
}
|
||||||
r.cache[id] = value
|
r.cache[id] = value
|
||||||
|
log.Println("Fetched property type group by ID:", value)
|
||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupsByParentId(parentId int) ([]models.PropertyTypeGroup, error) {
|
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)
|
rows, err := r.db.Query("SELECT id, name, description, parent_property_type_group_id, image_url FROM properties.property_types_groups WHERE parent_property_type_group_id = $1", parentId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -59,34 +62,30 @@ func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupsByParentId(parentId i
|
|||||||
return groups, nil
|
return groups, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *PropertyTypeGroupRepository) GetPropertyTypesByGroupId(gid int) ([]models.PropertyTypeGroup, error) {
|
func (r *PropertyTypeGroupRepository) GetPropertyTypesByGroupId(gid int) ([]models.PropertyType, 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)
|
rows, err := r.db.Query("SELECT id, name, description, property_type_group_id, image_url FROM properties.property_types WHERE property_type_group_id = $1", gid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var groups []models.PropertyTypeGroup
|
var types []models.PropertyType
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var value models.PropertyTypeGroup
|
var value models.PropertyType
|
||||||
err := rows.Scan(&value.Id, &value.Name, &value.Description, &value.ParentPropertyTypeGroupId, &value.ImageURL)
|
err := rows.Scan(&value.Id, &value.Name, &value.Description, &value.PropertyTypeGroupId, &value.ImageURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, ok := r.cache[value.Id]; !ok {
|
types = append(types, value)
|
||||||
r.cache[value.Id] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
groups = append(groups, value)
|
|
||||||
}
|
}
|
||||||
if err = rows.Err(); err != nil {
|
if err = rows.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return groups, nil
|
return types, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *PropertyTypeGroupRepository) CreatePropertyTypeGroup(value models.PropertyTypeGroup) (models.PropertyTypeGroup, error) {
|
func (r *PropertyTypeGroupRepository) CreatePropertyTypeGroup(value models.PropertyTypeGroup) (models.PropertyTypeGroup, error) {
|
||||||
result, err := r.db.Exec("INSERT INTO property_type_groups (name) VALUES (?)", value.Name)
|
result, err := r.db.Exec("INSERT INTO properties.property_types_groups (name, description, parent_property_type_group_id, image_url) VALUES ($1, $2, $3, $4)", value.Name, value.Description, value.ParentPropertyTypeGroupId, value.ImageURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.PropertyTypeGroup{}, err
|
return models.PropertyTypeGroup{}, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func (r *PropertyTypeRepository) GetPropertyTypeByID(id int) (models.PropertyTyp
|
|||||||
return propertyType, nil
|
return propertyType, nil
|
||||||
}
|
}
|
||||||
var propertyType models.PropertyType
|
var propertyType models.PropertyType
|
||||||
err := r.db.QueryRow("SELECT id, name, description, image_url, property_types_groups_id FROM property_types WHERE id = ?", id).Scan(&propertyType.Id, &propertyType.Name, &propertyType.Description, &propertyType.ImageURL, &propertyType.PropertyTypesGroupsId)
|
err := r.db.QueryRow("SELECT id, name, description, image_url, property_type_group_id FROM properties.property_types WHERE id = $1", id).Scan(&propertyType.Id, &propertyType.Name, &propertyType.Description, &propertyType.ImageURL, &propertyType.PropertyTypeGroupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.PropertyType{}, err
|
return models.PropertyType{}, err
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ func (r *PropertyTypeRepository) GetPropertyTypeByID(id int) (models.PropertyTyp
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *PropertyTypeRepository) GetPropertyTypesByGroupID(pid int) ([]models.PropertyType, error) {
|
func (r *PropertyTypeRepository) GetPropertyTypesByGroupID(pid int) ([]models.PropertyType, error) {
|
||||||
rows, err := r.db.Query("SELECT id, name, description, image_url, property_types_groups_id FROM property_types WHERE property_types_groups_id = ?", pid)
|
rows, err := r.db.Query("SELECT id, name, description, image_url, property_type_group_id FROM properties.property_types WHERE property_type_group_id = $1", pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ func (r *PropertyTypeRepository) GetPropertyTypesByGroupID(pid int) ([]models.Pr
|
|||||||
var propertyTypes []models.PropertyType
|
var propertyTypes []models.PropertyType
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var propertyType models.PropertyType
|
var propertyType models.PropertyType
|
||||||
err := rows.Scan(&propertyType.Id, &propertyType.Name, &propertyType.Description, &propertyType.ImageURL, &propertyType.PropertyTypesGroupsId)
|
err := rows.Scan(&propertyType.Id, &propertyType.Name, &propertyType.Description, &propertyType.ImageURL, &propertyType.PropertyTypeGroupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ func (r *PropertyTypeRepository) GetPropertyTypesByGroupID(pid int) ([]models.Pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *PropertyTypeRepository) createPropertyType(propertyType models.PropertyType) (models.PropertyType, error) {
|
func (r *PropertyTypeRepository) createPropertyType(propertyType models.PropertyType) (models.PropertyType, error) {
|
||||||
result, err := r.db.Exec("INSERT INTO property_types (name, description, image_url, property_types_groups_id) VALUES (?, ?, ?, ?)", propertyType.Name, propertyType.Description, propertyType.ImageURL, propertyType.PropertyTypesGroupsId)
|
result, err := r.db.Exec("INSERT INTO properties.property_types (name, description, image_url, property_type_group_id) VALUES ($1, $2, $3, $4)", propertyType.Name, propertyType.Description, propertyType.ImageURL, propertyType.PropertyTypeGroupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.PropertyType{}, err
|
return models.PropertyType{}, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func (r *ValueRepository) GetValueByID(id int) (models.Value, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var value models.Value
|
var value models.Value
|
||||||
err := r.db.QueryRow("SELECT id, value, image_url FROM values WHERE id = ?", id).Scan(&value.Id, &value.Value, &value.ImageURL)
|
err := r.db.QueryRow("SELECT id, value, image_url FROM properties.values WHERE id = ?", id).Scan(&value.Id, &value.Value, &value.ImageURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.Value{}, err
|
return models.Value{}, err
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ func (r *ValueRepository) GetValueByID(id int) (models.Value, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *ValueRepository) GetValuesByPropertyId(pid int) ([]models.Value, error) {
|
func (r *ValueRepository) GetValuesByPropertyId(pid int) ([]models.Value, error) {
|
||||||
rows, err := r.db.Query("SELECT id, value, image_url, properties_id FROM values WHERE properties_id = ?", pid)
|
rows, err := r.db.Query("SELECT id, value, image_url, properties_id FROM properties.values WHERE properties_id = ?", pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ func (r *ValueRepository) GetValuesByPropertyId(pid int) ([]models.Value, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *ValueRepository) CreateValue(value models.Value) (models.Value, error) {
|
func (r *ValueRepository) CreateValue(value models.Value) (models.Value, error) {
|
||||||
result, err := r.db.Exec("INSERT INTO values (value, image_url, properties_id) VALUES (?, ?, ?)", value.Value, value.ImageURL, value.PropertiesId)
|
result, err := r.db.Exec("INSERT INTO properties.values (value, image_url, properties_id) VALUES (?, ?, ?)", value.Value, value.ImageURL, value.PropertiesId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return models.Value{}, err
|
return models.Value{}, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<nav class="col-2 col-s-12">
|
<nav class="col-2 col-s-12">
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<ul class="node" hx-get="/properties/0/childs" hx-trigger="click" hx-target="#node-0" hx-swap="outerHTML">
|
<ul class="node" hx-get="/properties/0/childs" hx-trigger="click" hx-swap="outerHTML">
|
||||||
<details closed>
|
<details closed>
|
||||||
<summary>
|
<summary>
|
||||||
Eigenschaften
|
Eigenschaften
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<summary>
|
<summary>
|
||||||
{{.Name}}
|
{{.Name}}
|
||||||
</summary>
|
</summary>
|
||||||
<!-- Die PropertyTypeGroup Subgruppen-->
|
|
||||||
{{- range .PropertyTypeGroups}}
|
{{- range .PropertyTypeGroups}}
|
||||||
<ul class="node" hx-get="/properties/{{.Id}}/childs" hx-trigger="click" hx-swap="outerHTML">
|
<ul class="node" hx-get="/properties/{{.Id}}/childs" hx-trigger="click" hx-swap="outerHTML">
|
||||||
<details closed>
|
<details closed>
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
</ul>
|
</ul>
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
||||||
<!-- die PropertyTypes der PropertyTypeGroup-->
|
|
||||||
{{- range .PropertyTypes}}
|
{{- range .PropertyTypes}}
|
||||||
<ul class="node">
|
<ul class="node">
|
||||||
<li>{{.Name}}</li>
|
<li>{{.Name}}</li>
|
||||||
@@ -24,3 +23,4 @@
|
|||||||
{{- end}}
|
{{- end}}
|
||||||
</details>
|
</details>
|
||||||
</ul>
|
</ul>
|
||||||
|
{{end}}
|
||||||
Reference in New Issue
Block a user