Value Services implementiert Teil 1

This commit is contained in:
2026-08-15 16:58:12 +02:00
parent 8c5ad6ceec
commit 58de339be8
7778 changed files with 868356 additions and 124 deletions
+71
View File
@@ -0,0 +1,71 @@
-- 1. Globale Sequence anlegen
CREATE SEQUENCE global_id_seq
START 1000000
INCREMENT 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 2. Value Table
-- Value Table
CREATE TABLE IF NOT EXISTS values (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
description TEXT,
propertyId BIGINT
);
-- Property Table
CREATE TABLE IF NOT EXISTS propertys (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
description TEXT,
propertyTypeId BIGINT,
productId BIGINT,
productGroupId BIGINT
);
-- PropertyType Table
CREATE TABLE IF NOT EXISTS propertyTypes(
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
description TEXT,
propertyId BIGINT
);
-- PropertyTypeGroupTable
CREATE TABLE IF NOT EXISTS propertyTypeGroups (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
description TEXT,
parentGroupId BIGINT
);
-- 3. Product Tables
-- Product Table
CREATE TABLE IF NOT EXISTS products (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
externalId TEXT,
description TEXT,
productGroupId BIGINT
);
-- ProductGroup Table
CREATE TABLE IF NOT EXISTS productGroups (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
description TEXT,
parentGroupId BIGINT
);
-- Media Table
CREATE TABLE IF NOT EXISTS media (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
description TEXT,
media TEXT,
mediaType TEXT,
externalId BIGINT
);
+192 -124
View File
@@ -1,15 +1,204 @@
# Simply CPQ Buildtime Server
Dieser Ordner enthält alle relevanten Dateien und Informationen zum Simply CPQ Buildtime Server. Dieser dient der Pflege von Produktdaten, Regeln, Konditionen und Administration der Simply CPQ Anwendung durch die Bereitstellung des Pflege-Servers.
## Design-Entscheidungen
- Jedes Objekt hat eine über die gesamte Datenbank hinweg eindeutige ID.
```plsql
-- 1. Globale Sequence anlegen
CREATE SEQUENCE global_id_seq
START 1000000
INCREMENT 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 2. Tabelle A mit globaler ID
CREATE TABLE tabelle_a (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
name TEXT NOT NULL
);
```
- Jedes Objekt hat mindestens eine getById Methode.
- Ein Objekt enthält keine Unterstrukturen direkt. Strukturen, wie z.B. Listen, werden durch entsprechende Relationen in der Datenbank und auf dem Server abgebildet. Baumstrukturen werden durch ParentIds aufgebaut.
- Die Clients müssen sich zum Aufbau der Gesamtstruktur die jeweiligen Unter-Objekte an der API abholen. Ggf. sind das rekursive Strukturen (Bäume).
- Jedes Objekt hat eine ID, ein Label und eine Beschreibung (description)
- Alle Namen fangen immer mit einem Kleinbuchstaben in der Datenbank an. Danach greift dann das "CamelCase" System. z.B. "propertyTypeId".
- Wertesystem von Simply CPQ
- Es gibt einen generellen Merkmalspool, welcher durch Kategorien entsprechend strukturiert werden kann.
- Eine Merkmalsdefinition hat einen Namen und verweißt auf ein Set von Werten (das definiert die maximale Ausprägung dieses Wertes an Produktgruppen oder Produkten)
- Als mögliche Werte gibt es nur Listen, die Strings enthalten. Ein terminaler Wert ist eine Liste mit genau einem String als Inhalt.
- Eine Produktgruppe kann Merkmale enthalten, die sich auf eine Merkmalsdefinition beziehen. Dabei kann die Liste der möglichen Werte (das Set) ggf. nach Bedarf eingeschränkt werden. Sie darf NIE erweitert werden (Monotonie-Bedingung).
- Eine Unterproduktgruppe "erbt" die Merkmale der Obergruppe und kann diese ggf. weiter einschränken.
- Ein Produkt "erbt" alle Merkmale der Produktgruppe, in der sie enthalten ist. Ggf. können die Werte eines Merkmals dann entsprechend eingeschränkt werden, aber NIE erweitert (Monotoniebedingung).
- Folgende Funktionen:
- createPropertyTypeGroup
- createPropertyTypeInPropertyTypeGroup
- createValueForPropertyTypeId
- deleteValueFromPropertyTypeId
- getValuesFromPropertyTypeId
- copyPropertyFromPropertyTypeIdForProductGroupId
- deletePropertyIdFromProductGroupId (und aus allen Untergruppen und Produkten)
- (copyPropertiesFromProductGroupIDToProductGroupId) (beim Anlegen einer Untergruppe)
- (copyPropertiesFromProductGroupIdToProductID) (beim Anlegen eines Produktes in einer Produktgruppe)
- deleteValueFromProperty
- getValuesFromProperty
- updateValueFromValueId
- add
- Produkte haben zusätzlich zur ID, Label und Beschreibung noch eine externalId.
- Der Merkmalspool ist eine Baumstruktur, in der sich Merkmalsdefinitionen einordnen lassen. Dabei handelt es sich um eine reine Strukturierungshilfe ohne weitere Bedeutung.
- Produktgruppen bilden Baumstrukturen und "vererben" ihre Merkmalslisten an ihre Unterstrukturen.
- Die Unterstrukturen können weitere Merkmale enthalten. "Vererbte" Merkmale können allerdings nur eingeschränkt und nicht erweitert werden (Monotonie)
- Auf allen Ebenen können Produktgruppen Produkte enthalten. Diese haben dann die Merkmale der Produktgruppe, können aber auch weitere Merkmale enthalten. Die Merkmale der Produktgruppe können nur eingeschränkt werden, nicht erweitert (Monotonie)
- Produkte können Stücklisten aus anderen Produkten und/oder Strukturknoten enthalten. Bei einem Strukturknoten handelt es sich um eine Liste von Produkten, aus der in der Laufzeit ein Produkt ausgewählt wird.
- Zu Produkten, Produktgruppen und Merkmalstypen können Mediendaten hinterlegt werden.
- Der Server liefert und erwartet JSON Daten.
## Datenbank aufsetzen:
```plsql
-- 1. Globale Sequence anlegen
CREATE SEQUENCE global_id_seq
START 1000000
INCREMENT 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
-- 2. Value Table
-- Value Table
CREATE TABLE IF NOT EXISTS values (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
description TEXT,
propertyId BIGINT
);
-- Property Table
CREATE TABLE IF NOT EXISTS propertys (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
description TEXT,
propertyTypeId BIGINT,
productId BIGINT,
productGroupId BIGINT
);
-- PropertyType Table
CREATE TABLE IF NOT EXISTS propertyTypes(
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
description TEXT,
propertyId BIGINT
);
-- PropertyTypeGroupTable
CREATE TABLE IF NOT EXISTS propertyTypeGroups (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
description TEXT,
parentGroupId BIGINT
);
-- 3. Product Tables
-- Product Table
CREATE TABLE IF NOT EXISTS products (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
externalId TEXT,
description TEXT,
productGroupId BIGINT
);
-- ProductGroup Table
CREATE TABLE IF NOT EXISTS productGroups (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
description TEXT,
parentGroupId BIGINT
);
-- Media Table
CREATE TABLE IF NOT EXISTS media (
id BIGINT PRIMARY KEY DEFAULT nextval('global_id_seq'),
Label TEXT,
description TEXT,
media TEXT,
mediaType TEXT,
externalId BIGINT
);
```
## Open Aufsetzen des Source Codes:
````
go mod init simplycpq
````
## Struktur des Server-Verzeichnisses:
```bash
./models # Enthält die Strukurdefinitionen
./server # Enthält den Datenbank- und Web-Server
./repositories # Enthält die Zugriffslayer für die Datenbank
./services # Enthält die Service-Layer
./controller # Bilden die Schnittstellen zur RESTFull API
./config # Code zur Auswertung der Applikationskonfiguration
config.toml # Einstellungsdatei für den Server
main.go # Das Server Hauptprogramm
```
## Open Source Bibliotheken, die hier genutzt werden
### Viper
Viper dient zum Laden uns Auswerten von Config-Dateien. In diesem Case werden die HTTP-Servereinstellungen und die Datenbankverbindung ausgewertet.
````
go get github.com/spf13/viper
````
### PostgreSQL
Die Datenbank des Systems ist in dem Datenbankmanagementsystem PostgreSQL abgelegt. Zum einen braucht es eine Installation des Systems, auf dem die Software Zugriff hat und zum anderen benötigt das System die entsprechenden PostgreSQL Treiber für Go.
````
@@ -17,137 +206,16 @@ go get github.com/lib/pq
````
### Gin Gonic
Webserver Library zum Routing der API.
````
go get -u github.com/gin-gonic/gin
go get github.com/gin-contrib/cors
````
## Einrichten des Servers:
## Server API
Die Server-API baut auf HTTP und auf REST auf. Antworten werden im JSON Format gesendet,ebenso, wie neu anzulegende Daten oder zu aktualisierende Daten.
### Languages
Dieses Paket dient der Verwaltung der zur Verfügung stehenden Sprachen für die Stammdaten-Übersetzungen.
#### hole alle Sprachen
````
get: http://server:port/languages
````
Dieser Request liefert alle Sprachen im JSON Format. Hier ein beispielhaftes Ergebnis:
````json
[
{
"id": 1,
"locale": "de_DE",
"language": "german"
},
{
"id": 2,
"locale": "en_EN",
"language": "english (EN)"
},
{
"id": 3,
"locale": "en_US",
"language": "english (US)"
},
{
"id": 5,
"locale": "fr-FR",
"language": "france"
},
{
"id": 6,
"locale": "it-IT",
"language": "italy"
}
]
````
#### Hole die Sprache mit einer bestimmten ID
````
get: http://server:port/language/id
z.B.
get: http://server:port/language/5
````
Dieser Request liefert die Sprache im JSON Format mit der angegebenen ID im Pfad. Hier ein beispielhaftes Ergebnis:
````json
{
"id": 5,
"locale": "fr-FR",
"language": "france"
}
````
Der Request mit der ID 4 in diesem Beispiel liefert einen Fehler, da eine Sprache mit der ID 4 nicht existiert:
````
get: http://server:port/language/4
````
#### Aktualisiere eine Sprache
````
put: http://server:port/language
inhalt: application/json
z.B.:
{
"id": 1,
"locale": "de-DE",
"language": "german"
}
````
Alter Datensatz mit falschem locale:
````json
{
"id": 1,
"locale": "de_DE",
"language": "german"
}
````
Neuer, korrigierter Datensatz:
````json
{
"id": 1,
"locale": "de-DE",
"language": "german"
}
````
#### Anlegen einer neuen Sprache
````
put: http://server:port/language
inhalt: application/json
z.B.:
{
"id": 1,
"locale": "de-de",
"language": "german"
}
````
Neuer Datensatz:
````json
{
"id": 7,
"locale": "de-de",
"language": "german"
}
````
ACHTUNG: Die "id" des Datensatzes im Body wurde nicht genutzt. Sie wird bei der Neuanlage von der Datenbank bestimmt.
#### Löschen eines Datensatzes
````
delete: http://server:port/language/id
z.B.:
delete: http://server:port/language/7
````
Der Beispielrequest löscht den im vorherigen Abschnit angelegten Datensatz wieder.
Die Server-API baut auf HTTP und auf REST auf. Antworten werden im JSON Format gesendet,ebenso, wie neu anzulegende Daten oder zu aktualisierende Daten.
+37
View File
@@ -0,0 +1,37 @@
{
"v": 12,
"name": "SimplyCPQ",
"folders": [],
"requests": [
{
"v": "17",
"name": "create ProperyTypeGroup",
"method": "POST",
"endpoint": "http://localhost:8088/createPropertyTypeGroup",
"params": [],
"headers": [],
"preRequestScript": "",
"testScript": "",
"auth": {
"authType": "inherit",
"authActive": true
},
"body": {
"contentType": "application/json",
"body": "{\n \"label\": \"Simply CPQ\",\n \"description\": \"Root Gruppe für den Merkmalspool\",\n \"parentGroupId\": 0\n}"
},
"requestVariables": [],
"responses": {},
"description": null
}
],
"headers": [],
"auth": {
"authType": "none",
"authActive": true
},
"variables": [],
"description": "",
"preRequestScript": "",
"testScript": ""
}
+16
View File
@@ -0,0 +1,16 @@
# Database configuration
# Connection string is in Go pq driver format:
# host=<host> port=<port> user=<databaseUser>
# password=<databaseUserPassword> dbname=<databaseName>
[database]
connection_string = "host=192.168.178.50 port=5432 user=tsindt password=XD14ko8d dbname=simply_cpq_master_data sslmode=disable"
driver_name = "postgres"
################################################################
# HTTP server configuration
[http]
server_address = ":8088"
################################################################
+19
View File
@@ -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,130 @@
package controller
import (
"net/http"
"simplycpq/models"
"simplycpq/services"
"github.com/gin-gonic/gin"
)
type ValueController struct {
valueService *services.ValueService
}
func NewValueController(valueService *services.ValueService) *ValueController {
return &ValueController{
valueService: valueService,
}
}
func (vc *ValueController) CreatePropertyTypeGroup(c *gin.Context) {
var propertyTypeGroup models.PropertyTypeGroup
if err := c.ShouldBindJSON(&propertyTypeGroup); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
createdGroup, err2 := vc.valueService.CreatePropertyTypeGroup(&propertyTypeGroup)
if err2 != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err2.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroup created", "data": createdGroup})
}
func (vc *ValueController) UpdatePropertyTypeGroup(c *gin.Context) {
var propertyTypeGroup models.PropertyTypeGroup
if err := c.ShouldBindJSON(&propertyTypeGroup); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroup updated", "data": propertyTypeGroup})
}
func (vc *ValueController) DeletePropertyTypeGroup(c *gin.Context) {
id := c.Param("id")
c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroup deleted", "id": id})
}
func (vc *ValueController) GetPropertyTypeGroup(c *gin.Context) {
id := c.Param("id")
c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroup retrieved", "id": id})
}
func (vc *ValueController) GetPropertyTypeGroupsByParentId(c *gin.Context) {
parentId := c.Param("parentId")
c.JSON(http.StatusOK, gin.H{"message": "PropertyTypeGroups retrieved by parent ID", "parentId": parentId})
}
func (vc *ValueController) DeletePropertyTypeFromPropertyTypeGroupId(c *gin.Context) {
propertyTypeGroupId := c.Param("propertyTypeGroupId")
c.JSON(http.StatusOK, gin.H{"message": "PropertyType deleted from PropertyTypeGroup", "propertyTypeGroupId": propertyTypeGroupId})
}
func (vc *ValueController) CreatePropertyType(c *gin.Context) {
var propertyType models.PropertyType
if err := c.ShouldBindJSON(&propertyType); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "PropertyType created", "data": propertyType})
}
func (vc *ValueController) UpdatePropertyType(c *gin.Context) {
var propertyType models.PropertyType
if err := c.ShouldBindJSON(&propertyType); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "PropertyType updated", "data": propertyType})
}
func (vc *ValueController) DeletePropertyType(c *gin.Context) {
id := c.Param("id")
c.JSON(http.StatusOK, gin.H{"message": "PropertyType deleted", "id": id})
}
func (vc *ValueController) GetPropertyType(c *gin.Context) {
id := c.Param("id")
c.JSON(http.StatusOK, gin.H{"message": "PropertyType retrieved", "id": id})
}
func (vc *ValueController) GetPropertyTypesByGroupId(c *gin.Context) {
groupId := c.Param("groupId")
c.JSON(http.StatusOK, gin.H{"message": "PropertyTypes retrieved by group ID", "groupId": groupId})
}
func (vc *ValueController) CreateValueForPropertyTypeId(c *gin.Context) {
propertyTypeId := c.Param("propertyTypeId")
var value models.Value
if err := c.ShouldBindJSON(&value); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "Value created for PropertyType", "propertyTypeId": propertyTypeId, "data": value})
}
func (vc *ValueController) DeleteValueFromPropertyTypeId(c *gin.Context) {
propertyTypeId := c.Param("propertyTypeId")
c.JSON(http.StatusOK, gin.H{"message": "Value deleted from PropertyType", "propertyTypeId": propertyTypeId})
}
func (vc *ValueController) GetValuesFromPropertyTypeId(c *gin.Context) {
propertyTypeId := c.Param("propertyTypeId")
c.JSON(http.StatusOK, gin.H{"message": "Values retrieved from PropertyType", "propertyTypeId": propertyTypeId})
}
func (vc *ValueController) GetValuesFromPropertyId(c *gin.Context) {
propertyId := c.Param("propertyId")
c.JSON(http.StatusOK, gin.H{"message": "Values retrieved from Property", "propertyId": propertyId})
}
func (vc *ValueController) DeleteValueFromPropertyId(c *gin.Context) {
propertyId := c.Param("propertyId")
c.JSON(http.StatusOK, gin.H{"message": "Value deleted from Property", "propertyId": propertyId})
}
func (vc *ValueController) GetValue(c *gin.Context) {
id := c.Param("id")
c.JSON(http.StatusOK, gin.H{"message": "Value retrieved", "id": id})
}
+48
View File
@@ -0,0 +1,48 @@
module simplycpq
go 1.25.0
require (
github.com/bytedance/gopkg v0.1.4 // indirect
github.com/bytedance/sonic v1.15.2 // indirect
github.com/bytedance/sonic/loader v0.5.2 // indirect
github.com/cloudwego/base64x v0.1.7 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.15 // indirect
github.com/gin-contrib/cors v1.7.7 // indirect
github.com/gin-contrib/sse v1.1.1 // indirect
github.com/gin-gonic/gin v1.12.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.30.3 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/goccy/go-json v0.10.6 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.4.0 // indirect
github.com/leodido/go-urn v1.5.0 // indirect
github.com/lib/pq v1.12.3 // indirect
github.com/mattn/go-isatty v0.0.24 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.4.3 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.61.0 // indirect
github.com/sagikazarmark/locafero v0.11.0 // indirect
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/spf13/viper v1.21.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.2 // indirect
go.mongodb.org/mongo-driver/v2 v2.8.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.30.0 // indirect
golang.org/x/crypto v0.55.0 // indirect
golang.org/x/net v0.58.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/text v0.41.0 // indirect
google.golang.org/protobuf v1.36.12 // indirect
)
+107
View File
@@ -0,0 +1,107 @@
github.com/bytedance/gopkg v0.1.4 h1:oZnQwnX82KAIWb7033bEwtxvTqXcYMxDBaQxo5JJHWM=
github.com/bytedance/gopkg v0.1.4/go.mod h1:v1zWfPm21Fb+OsyXN2VAHdL6TBb2L88anLQgdyje6R4=
github.com/bytedance/sonic v1.15.2 h1:90H+rcF/FwLXwfB1cudOLq/je83n683Utf4Cbp0xHCo=
github.com/bytedance/sonic v1.15.2/go.mod h1:mT2NbXunuaEbnZ+mRIX/vYqKISmgEuHFDI4UzmKx2SA=
github.com/bytedance/sonic/loader v0.5.2 h1:0QtP1gevc1OZ6/H8Lb9BRZiCXd1Ftjd3OKuj1T1lBIo=
github.com/bytedance/sonic/loader v0.5.2/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo=
github.com/cloudwego/base64x v0.1.7 h1:NppS+Fgzg5ovhn4NkUXaDT3x9jldgH5ToMCqzBSi2zI=
github.com/cloudwego/base64x v0.1.7/go.mod h1:Cu1PV9zfrSf7ET2tIbWbbEy7jO7HHJ13q4X2SQ8aWYg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/gabriel-vasile/mimetype v1.4.15 h1:05iP/CYtZ/w455R/KZM6rZ5ieAdh99UPtd+d3YzLmaI=
github.com/gabriel-vasile/mimetype v1.4.15/go.mod h1:azpTcoLcDZRNgFou5j+APrqQx9HqVPWa6ijYQIIVswQ=
github.com/gin-contrib/cors v1.7.7 h1:Oh9joP463x7Mw72vhvJ61YQm8ODh9b04YR7vsOErD0Q=
github.com/gin-contrib/cors v1.7.7/go.mod h1:K5tW0RkzJtWSiOdikXloy8VEZlgdVNpHNw8FpjUPNrE=
github.com/gin-contrib/sse v1.1.1 h1:uGYpNwTacv5R68bSGMapo62iLTRa9l5zxGCps4hK6ko=
github.com/gin-contrib/sse v1.1.1/go.mod h1:QXzuVkA0YO7o/gun03UI1Q+FTI8ZV/n5t03kIQAI89s=
github.com/gin-gonic/gin v1.12.0 h1:b3YAbrZtnf8N//yjKeU2+MQsh2mY5htkZidOM7O0wG8=
github.com/gin-gonic/gin v1.12.0/go.mod h1:VxccKfsSllpKshkBWgVgRniFFAzFb9csfngsqANjnLc=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.30.3 h1:4MU6YkEwx7GbcPJOZxrtbu+QfF3pJLJuaYTeAH0DYy8=
github.com/go-playground/validator/v10 v10.30.3/go.mod h1:4Axh7oCNGcoGkqLoE4YWt6n20mcEIsPRlB7vPk3lpyc=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/goccy/go-json v0.10.6 h1:p8HrPJzOakx/mn/bQtjgNjdTcN+/S6FcG2CTtQOrHVU=
github.com/goccy/go-json v0.10.6/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.4.0 h1:S6Hrbc7+ywsr0r+RLapfGBHfyefhCTwEh3A0tV913Dw=
github.com/klauspost/cpuid/v2 v2.4.0/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU=
github.com/leodido/go-urn v1.5.0 h1:pLqT2kq1zpHW/1D18QMjMpdtX7cekxqtJJjg5ANyWw0=
github.com/leodido/go-urn v1.5.0/go.mod h1:9BORnCDhdPBJNDEX+w1bJisa8yOKYi116VeO96s4ifE=
github.com/lib/pq v1.12.3 h1:tTWxr2YLKwIvK90ZXEw8GP7UFHtcbTtty8zsI+YjrfQ=
github.com/lib/pq v1.12.3/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=
github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI=
github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pelletier/go-toml/v2 v2.4.3 h1:GTRvJQutkOSftxIFD5xw9aepkYNuPWmVJpffdDPYVpY=
github.com/pelletier/go-toml/v2 v2.4.3/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
github.com/quic-go/quic-go v0.61.0 h1:ui88A53s8MSVYLC56en0KQ17HARk+9986Dn0SBfKNvA=
github.com/quic-go/quic-go v0.61.0/go.mod h1:9So2anK4Tp22URSQq00k+Vo2PNkle96ycDPDHL4s9vs=
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.3.2 h1:zkEASHHyEClGeURfgNT9PJZVfAbs9oEX9QXggwWNJbc=
github.com/ugorji/go/codec v1.3.2/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=
go.mongodb.org/mongo-driver/v2 v2.8.0 h1:CxWDGQYY8QQwNjAl/aq2sfWakdnWZynnqJ9F4DhHbP8=
go.mongodb.org/mongo-driver/v2 v2.8.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/arch v0.30.0 h1:sB9h+1gRGa2+LauFSV0tm8bK1J2yo1bx6/Uyi/P6DTU=
golang.org/x/arch v0.30.0/go.mod h1:0X+GdSIP+kL5wPmpK7sdkEVTt2XoYP0cSjQSbZBwOi8=
golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M=
golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis=
golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To=
golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8=
golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+23
View File
@@ -0,0 +1,23 @@
package main
import (
"log"
_ "github.com/lib/pq"
"simplycpq/config"
"simplycpq/server"
)
func main() {
log.Println("Starting Simply CPQ Editor Service")
log.Println("Reading configuration")
config := config.InitConfig("config")
log.Println("Initializing database")
dbHandler := server.InitDatabase(config)
log.Println("Initializing HTTP server")
httpServer := server.InitHttpServer(config, dbHandler)
httpServer.Start()
log.Println("Service Stopped")
}
+25
View File
@@ -0,0 +1,25 @@
package models
type ProductGroup struct {
ID int `json:"id"`
Label string `json:"label"`
Description string `json:"description"`
ParentGroupID int `json:"parentGroupId"`
}
type Product struct {
ID int `json:"id"`
Label string `json:"label"`
ExternalID string `json:"externalId"`
Description string `json:"description"`
ProductGroupID int `json:"productGroupId"`
}
type Media struct {
ID int `json:"id"`
Label string `json:"label"`
Description string `json:"description"`
Media string `json:"media"`
MediaType string `json:"mediaType"`
ExternalID int `json:"externalId"`
}
+29
View File
@@ -0,0 +1,29 @@
package models
type PropertyTypeGroup struct {
ID int `json:"id"`
Label string `json:"label"`
Description string `json:"description"`
ParentGroupID int `json:"parentGroupId"`
}
type PropertyType struct {
ID int `json:"id"`
Label string `json:"label"`
Description string `json:"description"`
PropertyTypeGroupID int `json:"propertyTypeGroupId"`
}
type Property struct {
ID int `json:"id"`
Label string `json:"label"`
Description string `json:"description"`
PropertyTypeID int `json:"propertyTypeId"`
}
type Value struct {
ID int `json:"id"`
Label string `json:"label"`
PropertyID int `json:"propertyId"`
Description string `json:"description"`
}
@@ -0,0 +1,288 @@
package repositories
import (
"database/sql"
"simplycpq/models"
)
type ValueRepository struct {
db *sql.DB
}
func NewValueRepository(db *sql.DB) *ValueRepository {
return &ValueRepository{
db: db,
}
}
func (vr *ValueRepository) CreatePropertyTypeGroup(propertyTypeGroup *models.PropertyTypeGroup) (*models.PropertyTypeGroup, error) {
// Implement the logic to insert the propertyTypeGroup into the database
query := `INSERT INTO propertytypegroups(label, description, parentGroupId) VALUES($1,$2,$3) RETURNING id`
rows, err := vr.db.Query(query, propertyTypeGroup.Label, propertyTypeGroup.Description, propertyTypeGroup.ParentGroupID)
if err != nil {
return nil, err
}
defer rows.Close()
var id int
if rows.Next() {
err := rows.Scan(&id)
if err != nil {
return nil, err
}
}
propertyTypeGroup.ID = id
return propertyTypeGroup, nil
}
func (vr *ValueRepository) UpdatePropertyTypeGroup(propertyTypeGroup *models.PropertyTypeGroup) error {
// Implement the logic to update the propertyTypeGroup in the database
query := `UPDATE propertytypegroups SET label=$1, description=$2, parentGroupId=$3 WHERE id=$4`
_, err := vr.db.Exec(query, propertyTypeGroup.Label, propertyTypeGroup.Description, propertyTypeGroup.ParentGroupID, propertyTypeGroup.ID)
if err != nil {
return err
}
return nil
}
func (vr *ValueRepository) DeletePropertyTypeGroup(id int) error {
// Implement the logic to delete the propertyTypeGroup from the database
query := `DELETE FROM propertytypegroups WHERE id=$1`
_, err := vr.db.Exec(query, id)
if err != nil {
return err
}
return nil
}
func (vr *ValueRepository) GetPropertyTypeGroup(id int) (*models.PropertyTypeGroup, error) {
// Implement the logic to retrieve the propertyTypeGroup from the database
query := `SELECT id, label, description, parentGroupId FROM propertytypegroups WHERE id=$1`
row := vr.db.QueryRow(query, id)
var propertyTypeGroup models.PropertyTypeGroup
err := row.Scan(&propertyTypeGroup.ID, &propertyTypeGroup.Label, &propertyTypeGroup.Description, &propertyTypeGroup.ParentGroupID)
if err != nil {
if err == sql.ErrNoRows {
return nil, nil
}
return nil, err
}
return &propertyTypeGroup, nil
}
func (vr *ValueRepository) GetPropertyTypeGroupsByParentId(parentId int) ([]*models.PropertyTypeGroup, error) {
// Implement the logic to retrieve the propertyTypeGroups by parentId from the database
query := `SELECT id, label, description, parentGroupId FROM propertytypegroups WHERE parentGroupId=$1`
rows, err := vr.db.Query(query, parentId)
if err != nil {
return nil, err
}
defer rows.Close()
var propertyTypeGroups []*models.PropertyTypeGroup
for rows.Next() {
var propertyTypeGroup models.PropertyTypeGroup
err := rows.Scan(&propertyTypeGroup.ID, &propertyTypeGroup.Label, &propertyTypeGroup.Description, &propertyTypeGroup.ParentGroupID)
if err != nil {
return nil, err
}
propertyTypeGroups = append(propertyTypeGroups, &propertyTypeGroup)
}
return propertyTypeGroups, nil
}
func (vr *ValueRepository) DeletePropertyTypeFromPropertyTypeGroupId(propertyTypeGroupId int) error {
// Implement the logic to delete the propertyType from the propertyTypeGroup in the database
query := `DELETE FROM propertytypes WHERE propertytypegroupid=$1`
_, err := vr.db.Exec(query, propertyTypeGroupId)
if err != nil {
return err
}
return nil
}
func (vr *ValueRepository) CreatePropertyType(propertyType *models.PropertyType) (*models.PropertyType, error) {
// Implement the logic to insert the propertyType into the database
query := `INSERT INTO propertytypes(label, description, propertytypegroupid) VALUES($1,$2,$3) RETURNING id`
err := vr.db.QueryRow(query, propertyType.Label, propertyType.Description, propertyType.PropertyTypeGroupID).Scan(&propertyType.ID)
if err != nil {
return nil, err
}
return propertyType, nil
}
func (vr *ValueRepository) UpdatePropertyType(propertyType *models.PropertyType) error {
// Implement the logic to update the propertyType in the database
query := `UPDATE propertytypes SET label=$1, description=$2, propertytypegroupid=$3 WHERE id=$4`
_, err := vr.db.Exec(query, propertyType.Label, propertyType.Description, propertyType.PropertyTypeGroupID, propertyType.ID)
if err != nil {
return err
}
return nil
}
func (vr *ValueRepository) DeletePropertyType(id int) error {
// Implement the logic to delete the propertyType from the database
query := `DELETE FROM propertytypes WHERE id=$1`
_, err := vr.db.Exec(query, id)
if err != nil {
return err
}
return nil
}
func (vr *ValueRepository) GetPropertyType(id int) (*models.PropertyType, error) {
// Implement the logic to retrieve the propertyType from the database
query := `SELECT id, label, description, propertytypegroupid FROM propertytypes WHERE id=$1`
row := vr.db.QueryRow(query, id)
var propertyType models.PropertyType
err := row.Scan(&propertyType.ID, &propertyType.Label, &propertyType.Description, &propertyType.PropertyTypeGroupID)
if err != nil {
return nil, err
}
return &propertyType, nil
}
func (vr *ValueRepository) GetPropertyTypesByGroupId(groupId int) ([]*models.PropertyType, error) {
// Implement the logic to retrieve the propertyTypes by groupId from the database
query := `SELECT id, label, description, propertytypegroupid FROM propertytypes WHERE propertytypegroupid=$1`
rows, err := vr.db.Query(query, groupId)
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.Label, &propertyType.Description, &propertyType.PropertyTypeGroupID)
if err != nil {
return nil, err
}
propertyTypes = append(propertyTypes, &propertyType)
}
if err = rows.Err(); err != nil {
return nil, err
}
return propertyTypes, nil
}
func (vr *ValueRepository) CreateValueForPropertyTypeId(propertyTypeId int, value *models.Value) (*models.Value, error) {
// Implement the logic to insert the value into the database for the given propertyTypeId
query := `INSERT INTO values(propertytypeid, label, description) VALUES($1,$2,$3) RETURNING id`
err := vr.db.QueryRow(query, propertyTypeId, value.Label, value.Description).Scan(&value.ID)
if err != nil {
return nil, err
}
return value, nil
}
func (vr *ValueRepository) DeleteValueFromPropertyTypeId(propertyTypeId int) error {
// Implement the logic to delete the value from the database for the given propertyTypeId
query := `DELETE FROM values WHERE propertytypeid=$1`
_, err := vr.db.Exec(query, propertyTypeId)
if err != nil {
return err
}
return nil
}
func (vr *ValueRepository) GetValuesFromPropertyTypeId(propertyTypeId int) ([]*models.Value, error) {
// Implement the logic to retrieve the values from the database for the given propertyTypeId
query := `SELECT id, label, description FROM values WHERE propertytypeid=$1`
rows, err := vr.db.Query(query, propertyTypeId)
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.Label, &value.Description)
if err != nil {
return nil, err
}
values = append(values, &value)
}
if err = rows.Err(); err != nil {
return nil, err
}
return values, nil
}
func (vr *ValueRepository) GetValuesFromPropertyId(propertyId int) ([]*models.Value, error) {
// Implement the logic to retrieve the values from the database for the given propertyId
query := `SELECT id, label, description, propertyId FROM values WHERE propertyId=$1`
rows, err := vr.db.Query(query, propertyId)
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.Label, &value.Description, &value.PropertyID)
if err != nil {
return nil, err
}
values = append(values, &value)
}
if err = rows.Err(); err != nil {
return nil, err
}
return values, nil
}
func (vr *ValueRepository) CreateValueForPropertyId(propertyId int, value *models.Value) (*models.Value, error) {
// Implement the logic to create a value for the given propertyId
query := `INSERT INTO values (propertyId, label, description) VALUES ($1, $2, $3) RETURNING id`
err := vr.db.QueryRow(query, propertyId, value.Label, value.Description).Scan(&value.ID)
if err != nil {
return nil, err
}
return value, nil
}
func (vr *ValueRepository) DeleteValueFromPropertyId(id int) error {
// Implement the logic to delete the value from the database for the given id
query := `DELETE FROM values WHERE id=$1`
_, err := vr.db.Exec(query, id)
if err != nil {
return err
}
return nil
}
func (vr *ValueRepository) GetValue(id int) (*models.Value, error) {
// Implement the logic to retrieve the value from the database for the given id
query := `SELECT id, label, description FROM values WHERE id=$1`
row := vr.db.QueryRow(query, id)
var value models.Value
err := row.Scan(&value.ID, &value.Label, &value.Description)
if err != nil {
return nil, err
}
return &value, nil
}
func (vr *ValueRepository) copyValuesFromPropertyTypeToProperty(propertyTypeId int, propertyId int) error {
// Implement the logic to copy values from a property type to a property
query := `INSERT INTO values (propertyId, label, description) SELECT $1, label, description FROM values WHERE propertytypeid=$2`
_, err := vr.db.Exec(query, propertyId, propertyTypeId)
if err != nil {
return err
}
return nil
}
func (vr *ValueRepository) copyValuesFromPropertyToProperty(propertyIdFrom int, propertyIdTo int) error {
// Implement the logic to copy values from one property to another
query := `INSERT INTO values (propertyId, label, description) SELECT $1, label, description FROM values WHERE propertyId=$2`
_, err := vr.db.Exec(query, propertyIdTo, propertyIdFrom)
if err != nil {
return err
}
return nil
}
+26
View File
@@ -0,0 +1,26 @@
package server
import (
"log"
"database/sql"
"github.com/spf13/viper"
_ "github.com/lib/pq"
)
func InitDatabase(config *viper.Viper) *sql.DB {
connectionString := config.GetString("database.connection_string")
driverName := config.GetString("database.driver_name")
if connectionString == "" {
log.Fatalf("Database connection string is missing")
}
dbHandler, err := sql.Open(driverName, connectionString)
if err != nil {
log.Fatalf("Error while initializing database: %v", err)
}
err = dbHandler.Ping()
if err != nil {
dbHandler.Close()
log.Fatalf("Error while validating database: %v", err)
}
return dbHandler
}
+79
View File
@@ -0,0 +1,79 @@
package server
import (
"database/sql"
"log"
"net/http"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
"simplycpq/controller"
"simplycpq/repositories"
"simplycpq/services"
)
type HttpServer struct {
config *viper.Viper
router *gin.Engine
dbHandler *sql.DB
valueController *controller.ValueController
}
func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
// repository initialisation:
valueRepository := repositories.NewValueRepository(dbHandler)
// service initialisation:
valueService := services.NewValueService(valueRepository)
// controller initialisation:
valueController := controller.NewValueController(valueService)
// Service API
router := gin.Default()
router.Use(cors.Default())
router.GET("/test", Test)
// Value centric routing
router.POST("/createPropertyTypeGroup", valueController.CreatePropertyTypeGroup) // create PropertyTypeGroup
router.PUT("/updatePropertyTypeGroup", valueController.UpdatePropertyTypeGroup) // update PropertyTypeGroup
router.DELETE("/deletePropertyTypeGroup/:id", valueController.DeletePropertyTypeGroup) // delete PropertyTypeGroup
router.GET("/getPropertyTypeGroup/:id", valueController.GetPropertyTypeGroup) // get PropertyTypeGroup by id
router.GET("/getPropertyTypeGroupsByParentId/:parentId", valueController.GetPropertyTypeGroupsByParentId) // get all PropertyTypeGroups by parent ID
router.DELETE("/deletePropertyTypeFromPropertyTypeGroupId/:propertyTypeGroupId", valueController.DeletePropertyTypeFromPropertyTypeGroupId) // delete PropertyType from PropertyTypeGroup by ID
router.POST("/createPropertyType", valueController.CreatePropertyType) // create PropertyType
router.PUT("/updatePropertyType", valueController.UpdatePropertyType) // update PropertyType
router.DELETE("/deletePropertyType/:id", valueController.DeletePropertyType) // delete PropertyType
router.GET("/getPropertyType/:id", valueController.GetPropertyType) // get PropertyType by id
router.GET("/getPropertyTypesByGroupId/:groupId", valueController.GetPropertyTypesByGroupId) // get all PropertyTypes by group ID
router.POST("/createValueForPropertyTypeId/:propertyTypeId", valueController.CreateValueForPropertyTypeId) // create Value for PropertyType by ID
router.DELETE("/deleteValueFromPropertyTypeId/:propertyTypeId", valueController.DeleteValueFromPropertyTypeId) // delete Value from PropertyType by ID
router.GET("/getValuesFromPropertyTypeId/:propertyTypeId", valueController.GetValuesFromPropertyTypeId) // get all Values from PropertyType by ID
router.GET("/getValuesFromPropertyId/:propertyId", valueController.GetValuesFromPropertyId) // get all Values from Property by ID
router.DELETE("/deleteValueFromPropertyId/:propertyId", valueController.DeleteValueFromPropertyId) // delete Value from Property by ID
router.GET("/getValue/:id", valueController.GetValue) // get Value by id
// Product centric routing
// server
return HttpServer{
config: config,
router: router,
dbHandler: dbHandler,
valueController: valueController,
}
}
func (hs HttpServer) Start() {
err := hs.router.Run(hs.config.GetString("http.server_address"))
if err != nil {
log.Fatalf("Error while starting HTTP server: %v", err)
}
}
func Test(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"message": "Test",
})
}
+88
View File
@@ -0,0 +1,88 @@
package services
import (
"simplycpq/models"
"simplycpq/repositories"
)
type ValueService struct {
valueRepository *repositories.ValueRepository
}
func NewValueService(valueRepository *repositories.ValueRepository) *ValueService {
return &ValueService{
valueRepository: valueRepository,
}
}
func (vs *ValueService) CreatePropertyTypeGroup(propertyTypeGroup *models.PropertyTypeGroup) (*models.PropertyTypeGroup, error) {
return vs.valueRepository.CreatePropertyTypeGroup(propertyTypeGroup)
}
func (vs *ValueService) UpdatePropertyTypeGroup(propertyTypeGroup *models.PropertyTypeGroup) error {
return vs.valueRepository.UpdatePropertyTypeGroup(propertyTypeGroup)
}
func (vs *ValueService) DeletePropertyTypeGroup(id int) error {
return vs.valueRepository.DeletePropertyTypeGroup(id)
}
func (vs *ValueService) GetPropertyTypeGroup(id int) (*models.PropertyTypeGroup, error) {
return vs.valueRepository.GetPropertyTypeGroup(id)
}
func (vs *ValueService) GetPropertyTypeGroupsByParentId(parentId int) ([]*models.PropertyTypeGroup, error) {
return vs.valueRepository.GetPropertyTypeGroupsByParentId(parentId)
}
func (vs *ValueService) DeletePropertyTypeFromPropertyTypeGroupId(propertyTypeGroupId int) error {
return vs.valueRepository.DeletePropertyTypeFromPropertyTypeGroupId(propertyTypeGroupId)
}
func (vs *ValueService) CreatePropertyType(propertyType *models.PropertyType) (*models.PropertyType, error) {
return vs.valueRepository.CreatePropertyType(propertyType)
}
func (vs *ValueService) UpdatePropertyType(propertyType *models.PropertyType) error {
return vs.valueRepository.UpdatePropertyType(propertyType)
}
func (vs *ValueService) DeletePropertyType(id int) error {
return vs.valueRepository.DeletePropertyType(id)
}
func (vs *ValueService) GetPropertyType(id int) (*models.PropertyType, error) {
return vs.valueRepository.GetPropertyType(id)
}
func (vs *ValueService) GetPropertyTypesByGroupId(groupId int) ([]*models.PropertyType, error) {
return vs.valueRepository.GetPropertyTypesByGroupId(groupId)
}
func (vs *ValueService) CreateValueForPropertyTypeId(propertyTypeId int, value *models.Value) (*models.Value, error) {
return vs.valueRepository.CreateValueForPropertyTypeId(propertyTypeId, value)
}
func (vs *ValueService) DeleteValueFromPropertyTypeId(propertyTypeId int) error {
return vs.valueRepository.DeleteValueFromPropertyTypeId(propertyTypeId)
}
func (vs *ValueService) GetValuesFromPropertyTypeId(propertyTypeId int) ([]*models.Value, error) {
return vs.valueRepository.GetValuesFromPropertyTypeId(propertyTypeId)
}
func (vs *ValueService) GetValuesFromPropertyId(propertyId int) ([]*models.Value, error) {
return vs.valueRepository.GetValuesFromPropertyId(propertyId)
}
func (vs *ValueService) DeleteValueFromPropertyId(id int) error {
return vs.valueRepository.DeleteValueFromPropertyId(id)
}
func (vs *ValueService) CreateValueForPropertyId(propertyId int, value *models.Value) (*models.Value, error) {
return vs.valueRepository.CreateValueForPropertyId(propertyId, value)
}
func (vs *ValueService) GetValue(id int) (*models.Value, error) {
return vs.valueRepository.GetValue(id)
}