Website Mockup for X-CPQ Editor with Tailwind and DaisyUI

This commit is contained in:
2026-08-30 22:57:43 +02:00
parent fbd3d63d17
commit ac56c2a8e8
45 changed files with 6858 additions and 0 deletions
@@ -0,0 +1,19 @@
package config
import (
"log"
"github.com/spf13/viper"
)
func InitConfig(fileName string) *viper.Viper {
config := viper.New()
config.SetConfigName(fileName)
config.AddConfigPath(".")
config.AddConfigPath("$HOME")
err := config.ReadInConfig()
if err != nil {
log.Fatal("Error while parsing configuration file! ", err)
}
return config
}
@@ -0,0 +1,7 @@
package models
type Product struct {
Id int
Name string
Properties []Property
}
@@ -0,0 +1,9 @@
package models
type Property struct {
Id int
Name string
Description string
Parent_Property *Property
Values []Value
}
@@ -0,0 +1,8 @@
package models
type Property_Type struct {
Id int
Name string
Description string
Property Property
}
@@ -0,0 +1,9 @@
package models
type Property_Types_Group struct {
Id int
Name string
Description string
Property_Types []Property_Type
Property_Types_Groups []Property_Types_Group
}
@@ -0,0 +1,6 @@
package models
type Value struct {
Id int
Value string
}
@@ -0,0 +1,122 @@
package repositories
import (
"database/sql"
"xcpq_editor/internal/models"
)
type Property_Repository struct {
db *sql.DB
vr *Value_Repository
}
func NewPropertyRepository(db *sql.DB, valueRepository *Value_Repository) *Property_Repository {
return &Property_Repository{
db: db,
vr: valueRepository,
}
}
func (pr *Property_Repository) CreateProperty(
property *models.Property,
parent_property *models.Property,
property_type *models.Property_Type,
product *models.Product) (*models.Property, error) {
// Implement the logic to create a new property in the database
var parent_property_id int
var property_type_id int
var product_id int
if product != nil {
product_id = product.Id
} else {
product_id = 0
}
if property_type != nil {
property_type_id = property_type.Id
} else {
property_type_id = 0
}
if parent_property != nil {
parent_property_id = parent_property.Id
} else {
parent_property_id = 0
}
query := `INSERT INTO properties (name, description, parent_property_id, property_type_id, product_id) VALUES ($1, $2, $3, $4, $5) RETURNING id`
err := pr.db.QueryRow(query, property.Name, property.Description, parent_property_id, property_type_id, product_id).Scan(&property.Id)
if err != nil {
return nil, err
}
if parent_property_id != 0 {
property.Parent_Property = parent_property
} else {
property.Parent_Property = nil
}
if property_type_id != 0 {
property_type.Property = *property
}
if product_id != 0 {
product.Properties = append(product.Properties, *property)
}
return property, nil
}
func (pr *Property_Repository) GetPropertyById(id int) (*models.Property, error) {
// Implement the logic to retrieve a property by its ID from the database
query := `SELECT id, name, description, parent_property_id FROM properties WHERE id = $1`
property := &models.Property{}
var parent_property_id int
err := pr.db.QueryRow(query, id).Scan(&property.Id, &property.Name, &property.Description, &parent_property_id)
if err != nil {
return nil, err
}
if parent_property_id != 0 {
parent_property, err := pr.GetPropertyById(parent_property_id)
if err == nil {
property.Parent_Property = parent_property
}
} else {
property.Parent_Property = nil
}
valuePtrs, err := pr.vr.GetValuesFromPropertyId(property.Id)
if err != nil {
return property, err
}
property.Values = make([]models.Value, 0, len(valuePtrs))
for _, value := range valuePtrs {
if value != nil {
property.Values = append(property.Values, *value)
}
}
return property, nil
}
func (pr *Property_Repository) UpdateProperty(property *models.Property) error {
// Implement the logic to update an existing property in the database
query := `UPDATE properties SET name=$1, description=$2 WHERE id=$3`
_, err := pr.db.Exec(query, property.Name, property.Description, property.Id)
return err
}
func (pr *Property_Repository) DeleteProperty(id int) error {
// Implement the logic to delete a property from the database
// First, delete all values associated with the property
err := pr.vr.DeleteValuesFromPropertyId(id)
if err != nil {
return err
}
query := `DELETE FROM properties WHERE id=$1`
_, err = pr.db.Exec(query, id)
return err
}
@@ -0,0 +1,76 @@
package repositories
import (
"database/sql"
"xcpq_editor/internal/models"
)
type Property_Type_Repository struct {
db *sql.DB
pr *Property_Repository
}
func NewPropertyTypeRepository(db *sql.DB, propertyRepository *Property_Repository) *Property_Type_Repository {
return &Property_Type_Repository{
db: db,
pr: propertyRepository,
}
}
func (ptr *Property_Type_Repository) CreatePropertyType(
property_type *models.Property_Type,
property_type_group *models.Property_Types_Group,
property *models.Property) (*models.Property_Type, error) {
// Implement the logic to create a new property type in the database
var property_type_group_id int
if property_type_group != nil {
property_type_group_id = property_type_group.Id
} else {
property_type_group_id = 0
}
query := `INSERT INTO property_types (name, description, property_type_group_id) VALUES ($1, $2, $3) RETURNING id`
err := ptr.db.QueryRow(query, property_type.Name, property_type.Description, property_type_group_id).Scan(&property_type.Id)
if err != nil {
return nil, err
}
if property_type_group_id != 0 {
property_type_group.Property_Types = append(property_type_group.Property_Types, *property_type)
}
createdProperty, err := ptr.pr.CreateProperty(property, nil, property_type, nil)
if err != nil {
return nil, err
}
property_type.Property = *createdProperty
return property_type, nil
}
func (ptr *Property_Type_Repository) GetPropertyTypeById(id int) (*models.Property_Type, error) {
// Implement the logic to retrieve a property type by its ID from the database
query := "SELECT id, name, description FROM property_types WHERE id = $1"
property_type := &models.Property_Type{}
err := ptr.db.QueryRow(query, id).Scan(&property_type.Id, &property_type.Name, &property_type.Description)
if err != nil {
return nil, err
}
property, err := ptr.pr.GetPropertyById(property_type.Id)
property_type.Property = *property
return property_type, nil
}
func (ptr *Property_Type_Repository) UpdatePropertyType(property_type *models.Property_Type) error {
// Implement the logic to update the label/description of an existing property type
query := `UPDATE property_types SET name=$1, description=$2 WHERE id=$3`
_, err := ptr.db.Exec(query, property_type.Name, property_type.Description, property_type.Id)
return err
}
func (ptr *Property_Type_Repository) DeletePropertyType(id int) error {
// Implement the logic to delete a property type from the database
query := `DELETE FROM property_types WHERE id=$1`
_, err := ptr.db.Exec(query, id)
return err
}
@@ -0,0 +1,80 @@
package repositories
import (
"database/sql"
"xcpq_editor/internal/models"
)
type Value_Repository struct {
db *sql.DB
}
func NewValueRepository(db *sql.DB) *Value_Repository {
return &Value_Repository{
db: db,
}
}
func (vr *Value_Repository) CreateValueForPropertyId(propertyId int, value *models.Value) (*models.Value, error) {
// Implement the logic to create a new value for the given propertyId in the database
query := `INSERT INTO values (propertyid, value) VALUES ($1, $2) RETURNING id`
err := vr.db.QueryRow(query, propertyId, value.Value).Scan(&value.Id)
if err != nil {
return nil, err
}
return value, nil
}
func (vr *Value_Repository) DeleteValueFromPropertyId(valueId int, propertyId int) error {
// Implement the logic to delete the value from the database for the given valueId and propertyId
query := `DELETE FROM values WHERE id=$1 AND propertyid=$2`
_, err := vr.db.Exec(query, valueId, propertyId)
return err
}
func (vr *Value_Repository) UpdateValue(value *models.Value) error {
// Implement the logic to update the value in the database for the given valueId
query := `UPDATE values SET value=$1 WHERE id=$2`
_, err := vr.db.Exec(query, value.Value, value.Id)
return err
}
func (vr *Value_Repository) GetValue(id int) (*models.Value, error) {
// Implement the logic to retrieve a value by its ID from the database
query := "SELECT id, value FROM values WHERE id = $1"
row := vr.db.QueryRow(query, id)
value := &models.Value{}
err := row.Scan(&value.Id, &value.Value)
if err != nil {
return nil, err
}
return value, nil
}
func (vr *Value_Repository) DeleteValuesFromPropertyId(propertyId int) error {
// Implement the logic to delete all values from the database for the given propertyId
query := `DELETE FROM values WHERE propertyid=$1`
_, err := vr.db.Exec(query, propertyId)
return err
}
func (vr *Value_Repository) GetValuesFromPropertyId(propertyId int) ([]*models.Value, error) {
// Implement the logic to retrieve all values from the database for the given propertyId
query := `SELECT id, value FROM values WHERE propertyid=$1`
rows, err := vr.db.Query(query, propertyId)
if err != nil {
return nil, err
}
defer rows.Close()
values := []*models.Value{}
for rows.Next() {
value := &models.Value{}
err := rows.Scan(&value.ID, &value.Value)
if err != nil {
return nil, err
}
values = append(values, value)
}
return values, nil
}