Compare commits
7
Commits
main
...
PropertyTypeTree
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
261ee7a772 | ||
|
|
9b5bc9cdc1 | ||
|
|
5b9c2a4dae | ||
|
|
7ae541aaa9 | ||
|
|
679a8a0a3e | ||
|
|
c65f36dc40 | ||
|
|
7bfea738af |
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Println("Starting XCPQ Editor Service")
|
||||
log.Println("Starting SimplyCPQ Editor Services")
|
||||
log.Println("Reading configuration")
|
||||
config := config.InitConfig("config")
|
||||
log.Println("Initializing database")
|
||||
@@ -19,5 +19,5 @@ func main() {
|
||||
httpServer := server.InitHttpServer(config, dbHandler)
|
||||
httpServer.Start()
|
||||
|
||||
log.Println("XCPQ Editor Service Stopped")
|
||||
log.Println("SimplyCPQ Editor Services Stopped")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -56,7 +56,7 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
||||
// static content
|
||||
router.Static("/static", "../static")
|
||||
router.GET("/", mainHandler.Home)
|
||||
router.GET("/properties/rootnodes", propertyTypeHandler.GetRootPropertyTypeGroups)
|
||||
router.GET("/properties/:id/childs", propertyTypeHandler.GetPropertyTypeGroupContentById)
|
||||
|
||||
//router.GET("/properties", handler.PropertiesHandler)
|
||||
/* old routes
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"SimplyCPQ2/internal/models"
|
||||
"SimplyCPQ2/internal/services"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -10,12 +13,70 @@ 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,
|
||||
}
|
||||
}
|
||||
|
||||
// Dummy Methode
|
||||
func (h *PropertyTypeHandler) GetRootPropertyTypeGroups(ctx *gin.Context) {
|
||||
// Implement the logic to get root property types groups here
|
||||
}
|
||||
|
||||
func (h *PropertyTypeHandler) GetPropertyTypeGroupContentById(ctx *gin.Context) {
|
||||
idParam := ctx.Param("id")
|
||||
// Convert idParam to an integer
|
||||
id, err := strconv.Atoi(idParam)
|
||||
if err != nil {
|
||||
ctx.JSON(400, gin.H{"error": "Invalid ID"})
|
||||
return
|
||||
}
|
||||
|
||||
var ptg models.PropertyTypeGroup
|
||||
if id != 0 {
|
||||
ptg, err = h.propertyTypeService.GetPropertyTypeGroupByID(id)
|
||||
if err != nil {
|
||||
ctx.JSON(500, gin.H{"error": "Failed to get property type group", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
ptg.Name = "Eigenschaften"
|
||||
ptg.Id = 0
|
||||
ptg.ParentPropertyTypeGroupId = 0
|
||||
}
|
||||
|
||||
// get property type groups by parent ID
|
||||
ptgs, err := h.propertyTypeService.GetPropertyTypeGroupsByParentId(id)
|
||||
if err != nil {
|
||||
ctx.JSON(500, gin.H{"error": "Failed to get property type group content", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// get property types by parent ID
|
||||
pts, err := h.propertyTypeService.GetPropertyTypesByGroupId(id)
|
||||
if err != nil {
|
||||
ctx.JSON(500, gin.H{"error": "Failed to get property types", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// template for response
|
||||
content := PropertyTypeGroupContent{
|
||||
Id: id,
|
||||
Name: ptg.Name,
|
||||
PropertyTypeGroups: ptgs,
|
||||
PropertyTypes: pts,
|
||||
}
|
||||
|
||||
ctx.HTML(http.StatusOK, "ptg_treeNode", content)
|
||||
|
||||
// Implement the logic to get property type group content by ID here using idParam
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package models
|
||||
|
||||
type Property struct {
|
||||
Id int `json:"id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
ImageURL string `json:"ImageURL,omitempty"`
|
||||
//Property_Type *Property_Type `json:"property_type,omitempty"`
|
||||
Parent_Property *Property `json:"parent_property,omitempty"`
|
||||
Products_Group *ProductGroup `json:"products_group,omitempty"`
|
||||
Product *Product `json:"products,omitempty"`
|
||||
Values []Value `json:"values,omitempty"`
|
||||
Id int `json:"id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
ImageURL string `json:"ImageURL,omitempty"`
|
||||
PropertyTypeId int `json:"property_type_id,omitempty"`
|
||||
ParentPropertyId int `json:"parent_property_id,omitempty"`
|
||||
ProductGroupId int `json:"product_group_id,omitempty"`
|
||||
ProductId int `json:"product_id,omitempty"`
|
||||
Values []Value `json:"values,omitempty"`
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package models
|
||||
|
||||
type Property_Type struct {
|
||||
Id int `json:"id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
ImageURL string `json:"ImageURL,omitempty"`
|
||||
Property Property `json:"property"`
|
||||
type PropertyType struct {
|
||||
Id int `json:"id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
ImageURL string `json:"image_url,omitempty"`
|
||||
PropertyTypeGroupId int `json:"property_types_groups_id,omitempty"`
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package models
|
||||
|
||||
type PropertyTypeGroup struct {
|
||||
Id int `json:"id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
ImageURL string `json:"ImageURL,omitempty"`
|
||||
PropertyTypes []Property_Type `json:"PropertyTypes,omitempty"`
|
||||
PropertyTypeGroups []PropertyTypeGroup `json:"PropertyTypeGroups,omitempty"`
|
||||
Id int `json:"id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
ImageURL string `json:"ImageURL,omitempty"`
|
||||
ParentPropertyTypeGroupId int `json:"parent_property_type_group_id,omitempty"`
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package models
|
||||
|
||||
type Value struct {
|
||||
Id int `json:"id,omitempty"`
|
||||
Value string `json:"value"`
|
||||
ImageURL string `json:"ImageURL,omitempty"`
|
||||
Id int `json:"id,omitempty"`
|
||||
Value string `json:"value"`
|
||||
ImageURL string `json:"ImageURL,omitempty"`
|
||||
PropertiesId int `json:"properties_id,omitempty"`
|
||||
}
|
||||
|
||||
@@ -1,17 +1,159 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"SimplyCPQ2/internal/models"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type PropertyRepository struct {
|
||||
db *sql.DB
|
||||
vr *ValueRepository
|
||||
db *sql.DB
|
||||
vr *ValueRepository
|
||||
cache map[int]models.Property
|
||||
}
|
||||
|
||||
func NewPropertyRepository(db *sql.DB, valueRepository *ValueRepository) *PropertyRepository {
|
||||
return &PropertyRepository{
|
||||
db: db,
|
||||
vr: valueRepository,
|
||||
db: db,
|
||||
vr: valueRepository,
|
||||
cache: make(map[int]models.Property),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *PropertyRepository) createProperty(property models.Property) (models.Property, error) {
|
||||
result, err := r.db.Exec("INSERT INTO properties (name, description, image_url, parent_property_id, property_type_id, product_groups_id, products_id) VALUES (?, ?, ?, ?, ?, ?, ?)", property.Name, property.Description, property.ImageURL, property.ParentPropertyId, property.PropertyTypeId, property.ProductGroupId, property.ProductId)
|
||||
if err != nil {
|
||||
return models.Property{}, err
|
||||
}
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return models.Property{}, err
|
||||
}
|
||||
property.Id = int(id)
|
||||
r.cache[property.Id] = property
|
||||
return property, nil
|
||||
}
|
||||
|
||||
func (r *PropertyRepository) GetPropertyByID(id int) (models.Property, error) {
|
||||
if property, ok := r.cache[id]; ok {
|
||||
return property, nil
|
||||
}
|
||||
|
||||
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.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 {
|
||||
return models.Property{}, err
|
||||
}
|
||||
r.cache[property.Id] = property
|
||||
return property, nil
|
||||
}
|
||||
|
||||
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.properties WHERE product_groups_id = $1", pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var properties []models.Property
|
||||
for rows.Next() {
|
||||
var property models.Property
|
||||
err := rows.Scan(&property.Id, &property.Name, &property.Description, &property.ImageURL, &property.ParentPropertyId, &property.PropertyTypeId, &property.ProductGroupId, &property.ProductId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cachedProperty, ok := r.cache[property.Id]; ok {
|
||||
properties = append(properties, cachedProperty)
|
||||
} else {
|
||||
r.cache[property.Id] = property
|
||||
properties = append(properties, property)
|
||||
}
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return properties, nil
|
||||
}
|
||||
|
||||
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.properties WHERE products_id = $1", pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var properties []models.Property
|
||||
for rows.Next() {
|
||||
var property models.Property
|
||||
err := rows.Scan(&property.Id, &property.Name, &property.Description, &property.ImageURL, &property.ParentPropertyId, &property.PropertyTypeId, &property.ProductGroupId, &property.ProductId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cachedProperty, ok := r.cache[property.Id]; ok {
|
||||
properties = append(properties, cachedProperty)
|
||||
} else {
|
||||
r.cache[property.Id] = property
|
||||
properties = append(properties, property)
|
||||
}
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return properties, nil
|
||||
}
|
||||
|
||||
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.properties WHERE parent_property_id = $1", pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var properties []models.Property
|
||||
for rows.Next() {
|
||||
var property models.Property
|
||||
err := rows.Scan(&property.Id, &property.Name, &property.Description, &property.ImageURL, &property.ParentPropertyId, &property.PropertyTypeId, &property.ProductGroupId, &property.ProductId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cachedProperty, ok := r.cache[property.Id]; ok {
|
||||
properties = append(properties, cachedProperty)
|
||||
} else {
|
||||
r.cache[property.Id] = property
|
||||
properties = append(properties, property)
|
||||
}
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return properties, nil
|
||||
}
|
||||
|
||||
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.properties WHERE property_type_id = $1", pid)
|
||||
if err != nil {
|
||||
return models.Property{}, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var properties []models.Property
|
||||
for rows.Next() {
|
||||
var property models.Property
|
||||
err := rows.Scan(&property.Id, &property.Name, &property.Description, &property.ImageURL, &property.ParentPropertyId, &property.PropertyTypeId, &property.ProductGroupId, &property.ProductId)
|
||||
if err != nil {
|
||||
return models.Property{}, err
|
||||
}
|
||||
if cachedProperty, ok := r.cache[property.Id]; ok {
|
||||
properties = append(properties, cachedProperty)
|
||||
} else {
|
||||
r.cache[property.Id] = property
|
||||
properties = append(properties, property)
|
||||
}
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return models.Property{}, err
|
||||
}
|
||||
if len(properties) == 0 {
|
||||
return models.Property{}, nil
|
||||
}
|
||||
return properties[0], nil
|
||||
}
|
||||
|
||||
@@ -1,17 +1,99 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"SimplyCPQ2/internal/models"
|
||||
"database/sql"
|
||||
"log"
|
||||
)
|
||||
|
||||
type PropertyTypeGroupRepository struct {
|
||||
db *sql.DB
|
||||
PropertyTypeRepository *PropertyTypeRepository
|
||||
cache map[int]models.PropertyTypeGroup
|
||||
}
|
||||
|
||||
func NewPropertyTypesGroupRepository(db *sql.DB, PropertyTypeRepository *PropertyTypeRepository) *PropertyTypeGroupRepository {
|
||||
return &PropertyTypeGroupRepository{
|
||||
db: db,
|
||||
PropertyTypeRepository: PropertyTypeRepository,
|
||||
cache: make(map[int]models.PropertyTypeGroup),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupByID(id int) (models.PropertyTypeGroup, error) {
|
||||
if value, ok := r.cache[id]; ok {
|
||||
return value, nil
|
||||
}
|
||||
log.Println("Fetching property type group by ID:", id)
|
||||
var value models.PropertyTypeGroup
|
||||
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 {
|
||||
log.Println("Error fetching property type group by ID:", err)
|
||||
return models.PropertyTypeGroup{}, err
|
||||
}
|
||||
r.cache[id] = value
|
||||
log.Println("Fetched property type group by ID:", value)
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupsByParentId(parentId int) ([]models.PropertyTypeGroup, error) {
|
||||
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 {
|
||||
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.PropertyType, error) {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var types []models.PropertyType
|
||||
for rows.Next() {
|
||||
var value models.PropertyType
|
||||
err := rows.Scan(&value.Id, &value.Name, &value.Description, &value.PropertyTypeGroupId, &value.ImageURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
types = append(types, value)
|
||||
}
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return types, nil
|
||||
}
|
||||
|
||||
func (r *PropertyTypeGroupRepository) CreatePropertyTypeGroup(value models.PropertyTypeGroup) (models.PropertyTypeGroup, error) {
|
||||
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 {
|
||||
return models.PropertyTypeGroup{}, err
|
||||
}
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return models.PropertyTypeGroup{}, err
|
||||
}
|
||||
value.Id = int(id)
|
||||
r.cache[value.Id] = value
|
||||
return value, nil
|
||||
}
|
||||
|
||||
@@ -1,17 +1,74 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"SimplyCPQ2/internal/models"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type PropertyTypeRepository struct {
|
||||
db *sql.DB
|
||||
pr *PropertyRepository
|
||||
db *sql.DB
|
||||
pr *PropertyRepository
|
||||
cache map[int]models.PropertyType
|
||||
}
|
||||
|
||||
func NewPropertyTypeRepository(db *sql.DB, propertyRepository *PropertyRepository) *PropertyTypeRepository {
|
||||
return &PropertyTypeRepository{
|
||||
db: db,
|
||||
pr: propertyRepository,
|
||||
db: db,
|
||||
pr: propertyRepository,
|
||||
cache: make(map[int]models.PropertyType),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *PropertyTypeRepository) GetPropertyTypeByID(id int) (models.PropertyType, error) {
|
||||
if propertyType, ok := r.cache[id]; ok {
|
||||
return propertyType, nil
|
||||
}
|
||||
var propertyType models.PropertyType
|
||||
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 {
|
||||
return models.PropertyType{}, err
|
||||
}
|
||||
r.cache[id] = propertyType
|
||||
return propertyType, nil
|
||||
}
|
||||
|
||||
func (r *PropertyTypeRepository) GetPropertyTypesByGroupID(pid int) ([]models.PropertyType, error) {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var propertyTypes []models.PropertyType
|
||||
for rows.Next() {
|
||||
var propertyType models.PropertyType
|
||||
err := rows.Scan(&propertyType.Id, &propertyType.Name, &propertyType.Description, &propertyType.ImageURL, &propertyType.PropertyTypeGroupId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cachedPropertyType, ok := r.cache[propertyType.Id]; ok {
|
||||
propertyTypes = append(propertyTypes, cachedPropertyType)
|
||||
} else {
|
||||
r.cache[propertyType.Id] = propertyType
|
||||
propertyTypes = append(propertyTypes, propertyType)
|
||||
}
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return propertyTypes, nil
|
||||
}
|
||||
|
||||
func (r *PropertyTypeRepository) createPropertyType(propertyType models.PropertyType) (models.PropertyType, error) {
|
||||
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 {
|
||||
return models.PropertyType{}, err
|
||||
}
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return models.PropertyType{}, err
|
||||
}
|
||||
propertyType.Id = int(id)
|
||||
r.cache[propertyType.Id] = propertyType
|
||||
return propertyType, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"SimplyCPQ2/internal/models"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type ValueRepository struct {
|
||||
db *sql.DB
|
||||
cache map[int]models.Value
|
||||
}
|
||||
|
||||
func NewValueRepository(db *sql.DB) *ValueRepository {
|
||||
return &ValueRepository{
|
||||
db: db,
|
||||
cache: make(map[int]models.Value),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ValueRepository) GetValueByID(id int) (models.Value, error) {
|
||||
if value, ok := r.cache[id]; ok {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
var value models.Value
|
||||
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 {
|
||||
return models.Value{}, err
|
||||
}
|
||||
r.cache[id] = value
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (r *ValueRepository) GetValuesByPropertyId(pid int) ([]models.Value, error) {
|
||||
rows, err := r.db.Query("SELECT id, value, image_url, properties_id FROM properties.values WHERE properties_id = ?", pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var values []models.Value
|
||||
for rows.Next() {
|
||||
var value models.Value
|
||||
err := rows.Scan(&value.Id, &value.Value, &value.ImageURL, &value.PropertiesId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cachedValue, ok := r.cache[value.Id]; ok {
|
||||
values = append(values, cachedValue)
|
||||
} else {
|
||||
r.cache[value.Id] = value
|
||||
values = append(values, value)
|
||||
}
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
func (r *ValueRepository) CreateValue(value models.Value) (models.Value, error) {
|
||||
result, err := r.db.Exec("INSERT INTO properties.values (value, image_url, properties_id) VALUES (?, ?, ?)", value.Value, value.ImageURL, value.PropertiesId)
|
||||
if err != nil {
|
||||
return models.Value{}, err
|
||||
}
|
||||
id, err := result.LastInsertId()
|
||||
if err != nil {
|
||||
return models.Value{}, err
|
||||
}
|
||||
value.Id = int(id)
|
||||
r.cache[value.Id] = value
|
||||
return value, nil
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type ValueRepository struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
||||
func NewValueRepository(db *sql.DB) *ValueRepository {
|
||||
return &ValueRepository{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,45 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"SimplyCPQ2/internal/models"
|
||||
"SimplyCPQ2/internal/repositories"
|
||||
)
|
||||
|
||||
type PropertyTypeService struct {
|
||||
// Add any dependencies or fields needed for the service here
|
||||
values_Repository *repositories.ValueRepository
|
||||
Property_Repository *repositories.PropertyRepository
|
||||
PropertyTypes_Repository *repositories.PropertyTypeRepository
|
||||
PropertyTypeGroups_Repository *repositories.PropertyTypeGroupRepository
|
||||
}
|
||||
|
||||
func NewPropertyTypeService(propertyTypesRepo *repositories.PropertyTypeRepository, propertyTypesGroupsRepo *repositories.PropertyTypeGroupRepository) *PropertyTypeService {
|
||||
func NewPropertyTypeService(propertyRepo *repositories.PropertyRepository, propertyTypesRepo *repositories.PropertyTypeRepository, propertyTypesGroupsRepo *repositories.PropertyTypeGroupRepository, valuesRepo *repositories.ValueRepository) *PropertyTypeService {
|
||||
return &PropertyTypeService{
|
||||
Property_Repository: propertyRepo,
|
||||
PropertyTypes_Repository: propertyTypesRepo,
|
||||
PropertyTypeGroups_Repository: propertyTypesGroupsRepo,
|
||||
values_Repository: valuesRepo,
|
||||
}
|
||||
}
|
||||
|
||||
// Getter functions
|
||||
|
||||
func (service *PropertyTypeService) GetPropertyTypeGroupsByParentId(parentId int) ([]models.PropertyTypeGroup, error) {
|
||||
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) {
|
||||
return service.PropertyTypes_Repository.GetPropertyTypesByGroupID(id)
|
||||
}
|
||||
|
||||
func (service *PropertyTypeService) GetPropertyByTypeId(id int) (models.Property, error) {
|
||||
return service.Property_Repository.GetPropertyByPropertyTypeID(id)
|
||||
}
|
||||
|
||||
func (service *PropertyTypeService) GetValuesByPropertyId(id int) ([]models.Value, error) {
|
||||
return service.values_Repository.GetValuesByPropertyId(id)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="/static/css/scpq_global.css">
|
||||
<link rel="stylesheet" href="/static/css/scpq_header.css">
|
||||
<link rel="stylesheet" href="/static/css/scpq_footer.css">
|
||||
<link rel="stylesheet" href="/static/css/scpq_content.css">
|
||||
<title>Simply CPQ Material Editor V2</title>
|
||||
</head>
|
||||
<body>
|
||||
<header class="row">
|
||||
<div class="col-8 col-s-12">
|
||||
<h1>Simply CPQ Material Editor V2</h1>
|
||||
</div>
|
||||
</header>
|
||||
<div class="row">
|
||||
<nav class="col-2 col-s-12">
|
||||
<ul>
|
||||
<li>
|
||||
<ul>
|
||||
<details closed>
|
||||
<summary>
|
||||
Eigenschaften
|
||||
</summary>
|
||||
<ul class="node">
|
||||
<li class="leaf"><a href="#">Unterpunkt 1</a></li>
|
||||
<li class="leaf"><a href="#">Unterpunkt 2</a></li>
|
||||
</ul>
|
||||
</details>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<ul>
|
||||
<details closed>
|
||||
<summary>
|
||||
Produkte
|
||||
</summary>
|
||||
<ul class="node">
|
||||
<li class="leaf"><a href="#">Unterpunkt 1</a></li>
|
||||
<li class="leaf"><a href="#">Unterpunkt 2</a></li>
|
||||
</ul>
|
||||
</details>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<ul>
|
||||
<details closed>
|
||||
<summary>
|
||||
Regeln
|
||||
</summary>
|
||||
<ul class="node">
|
||||
<li class="leaf"><a href="#">Unterpunkt 1</a></li>
|
||||
<li class="leaf"><a href="#">Unterpunkt 2</a></li>
|
||||
</ul>
|
||||
</details>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<ul>
|
||||
<details closed>
|
||||
<summary>
|
||||
Preiskalkulation
|
||||
</summary>
|
||||
<ul class="node">
|
||||
<li class="leaf"><a href="#">Unterpunkt 1</a></li>
|
||||
<li class="leaf"><a href="#">Unterpunkt 2</a></li>
|
||||
</ul>
|
||||
</details>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<ul>
|
||||
<details closed>
|
||||
<summary>
|
||||
Übersetzungen
|
||||
</summary>
|
||||
<ul class="node">
|
||||
<li class="leaf"><a href="#">Unterpunkt 1</a></li>
|
||||
<li class="leaf"><a href="#">Unterpunkt 2</a></li>
|
||||
</ul>
|
||||
</details>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<main>
|
||||
<div class="col-6 col-s-6">
|
||||
<h3>Property-Type Group </h3>
|
||||
<section class="editor-view">
|
||||
<section id="PropertyTypeGroupData">
|
||||
<form class="cform" method="post" action="/updatePropertyTypeGroup">
|
||||
<label for="propertyTypeGroupID">ID:</label>
|
||||
<input type="text" id="propertyTypeGroupID" name="propertyTypeGroupID" value="{PropertyTypeGroupID}" disabled>
|
||||
<label for="propertyTypeGroupName">Name:</label>
|
||||
<input type="text" id="propertyTypeGroupName" name="propertyTypeGroupName" value="{PropertyTypeGroupName}">
|
||||
<label for="propertyTypeGroupDescription">Beschreibung:</label>
|
||||
<textarea id="propertyTypeGroupDescription" name="propertyTypeGroupDescription">{PropertyTypeGroupDescription}</textarea>
|
||||
<div class="button_row">
|
||||
<button type="submit">Speichern</button>
|
||||
<button type="submit">Neu</button>
|
||||
<button type="submit">Löschen</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</section>
|
||||
</div>
|
||||
<div class="col-6 col-s-12">
|
||||
<div class="aside">
|
||||
<h3>Values für {PropertyTypeName}</h3>
|
||||
<section class="editor-view">
|
||||
<section id="ValueData">
|
||||
<table>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Value</th>
|
||||
<th>Description</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>Value 1</td>
|
||||
<td>Description 1</td>
|
||||
<td>
|
||||
<div class="button_row">
|
||||
<button type="button">Edit</button>
|
||||
<button type="button">Delete</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>Value 2</td>
|
||||
<td>Description 2</td>
|
||||
<td>
|
||||
<div class="button_row">
|
||||
<button type="button">Edit</button>
|
||||
<button type="button">Delete</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</section>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div> <!-- Closing the initial row div -->
|
||||
<footer class="row">
|
||||
<div class="col-12 col-s-12">
|
||||
<h6>© 2026 Simply CPQ - All rights reserved - contact: <a href="mailto:Thomas.Sindt@gmx.de">Thomas.Sindt@gmx.de</a></h6>
|
||||
</div>
|
||||
</footer> <!-- Closing the footer row div -->
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -7,6 +7,7 @@
|
||||
<link rel="stylesheet" href="/static/css/scpq_header.css">
|
||||
<link rel="stylesheet" href="/static/css/scpq_footer.css">
|
||||
<link rel="stylesheet" href="/static/css/scpq_content.css">
|
||||
<script src="/static/js/htmx.js"></script>
|
||||
<title>Simply CPQ Material Editor V2</title>
|
||||
</head>
|
||||
<body>
|
||||
@@ -19,15 +20,13 @@
|
||||
<nav class="col-2 col-s-12">
|
||||
<ul>
|
||||
<li>
|
||||
<ul>
|
||||
<ul class="node" hx-get="/properties/0/childs" hx-trigger="click" hx-swap="outerHTML">
|
||||
<details closed>
|
||||
<summary>
|
||||
Eigenschaften
|
||||
</summary>
|
||||
<ul class="node">
|
||||
<li class="leaf"><a href="#">Unterpunkt 1</a></li>
|
||||
<li class="leaf"><a href="#">Unterpunkt 2</a></li>
|
||||
</ul>
|
||||
<div id="node-0">Keine Informationen vorhanden
|
||||
</div>
|
||||
</details>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
{{define "ptg_treeNode"}}
|
||||
<!-- der eigentliche Knoten-->
|
||||
<ul class="node">
|
||||
<details open>
|
||||
<summary>
|
||||
{{.Name}}
|
||||
</summary>
|
||||
|
||||
{{- range .PropertyTypeGroups}}
|
||||
<ul class="node" hx-get="/properties/{{.Id}}/childs" hx-trigger="click" hx-swap="outerHTML">
|
||||
<details closed>
|
||||
<summary>
|
||||
{{.Name}}
|
||||
</summary>
|
||||
</details>
|
||||
</ul>
|
||||
{{- end}}
|
||||
|
||||
{{- range .PropertyTypes}}
|
||||
<ul class="node">
|
||||
<li>{{.Name}}</li>
|
||||
</ul>
|
||||
{{- end}}
|
||||
</details>
|
||||
</ul>
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user