Property Import
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
# password=<databaseUserPassword> dbname=<databaseName>
|
||||
|
||||
[database]
|
||||
##connection_string = "host=192.168.178.50 port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable"
|
||||
connection_string = "host=localhost port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable"
|
||||
connection_string = "host=192.168.178.50 port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable"
|
||||
##connection_string = "host=localhost port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable"
|
||||
driver_name = "postgres"
|
||||
|
||||
################################################################
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"xcpq_editor/internal/handlers"
|
||||
"xcpq_editor/internal/repositories"
|
||||
"xcpq_editor/internal/services"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -12,18 +14,33 @@ import (
|
||||
)
|
||||
|
||||
type HttpServer struct {
|
||||
config *viper.Viper
|
||||
router *gin.Engine
|
||||
dbHandler *sql.DB
|
||||
config *viper.Viper
|
||||
router *gin.Engine
|
||||
dbHandler *sql.DB
|
||||
importHandler *handlers.ImportHandler
|
||||
importRepository *repositories.Import_Repository
|
||||
valueRepository *repositories.Value_Repository
|
||||
propertyRepository *repositories.Property_Repository
|
||||
propertyTypeRepository *repositories.Property_Type_Repository
|
||||
propertyTypeGroupRepository *repositories.Property_Types_Group_Repository
|
||||
}
|
||||
|
||||
func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
||||
|
||||
// db initialization can be done here if needed
|
||||
|
||||
// repository initialisation:
|
||||
valueRepository := repositories.NewValueRepository(dbHandler)
|
||||
propertyRepository := repositories.NewPropertyRepository(dbHandler, valueRepository)
|
||||
propertyTypeRepository := repositories.NewPropertyTypeRepository(dbHandler, propertyRepository)
|
||||
propertyTypeGroupRepository := repositories.NewPropertyTypesGroupRepository(dbHandler, propertyTypeRepository)
|
||||
importRepository := repositories.NewImportRepository(dbHandler, valueRepository, propertyTypeRepository, propertyTypeGroupRepository, propertyRepository)
|
||||
|
||||
// service initialisation:
|
||||
importService := services.NewImportService(importRepository)
|
||||
|
||||
// controller initialisation:
|
||||
// handler initialisation:
|
||||
importHandler := handlers.NewImportHandler(importService)
|
||||
|
||||
// Service API
|
||||
router := gin.Default()
|
||||
@@ -40,16 +57,22 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
||||
*/
|
||||
|
||||
// import
|
||||
router.POST("/import", handlers.ImportHandler_PropertyTypesGroup)
|
||||
router.POST("/importPropertyTypes", importHandler.ImportPropertyTypeGroups)
|
||||
|
||||
// test endpoint
|
||||
router.GET("/test", Test)
|
||||
|
||||
// server
|
||||
return HttpServer{
|
||||
config: config,
|
||||
router: router,
|
||||
dbHandler: dbHandler,
|
||||
config: config,
|
||||
router: router,
|
||||
dbHandler: dbHandler,
|
||||
importHandler: importHandler,
|
||||
importRepository: importRepository,
|
||||
valueRepository: valueRepository,
|
||||
propertyRepository: propertyRepository,
|
||||
propertyTypeRepository: propertyTypeRepository,
|
||||
propertyTypeGroupRepository: propertyTypeGroupRepository,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,97 +1,286 @@
|
||||
[{
|
||||
"name": "Simply CPQ",
|
||||
"description": "Property Type Group for Simply CPQ",
|
||||
"property_types_groups": [
|
||||
{
|
||||
"name": "electrical",
|
||||
"description": "All electrical property types",
|
||||
"property_types": [
|
||||
{
|
||||
"name": "Spannungsversorgung (V)",
|
||||
"description": "Spannungsversorgung (V)"
|
||||
},
|
||||
{
|
||||
"name": "Leistung (W)",
|
||||
"description": "Leistung"
|
||||
},
|
||||
{
|
||||
"name": "Eingangsimpedanz (Ω)",
|
||||
"description": "Wiederstand der Eingangsimpedanz"
|
||||
},
|
||||
{
|
||||
"name": "Frequenzbereich (Hz‑kHz)",
|
||||
"description": "Frequenzbereich (Hz‑kHz)"
|
||||
},
|
||||
{
|
||||
"name": "Signal‑Rausch‑Verhältnis (dB)",
|
||||
"description": "Signal‑Rausch‑Verhältnis (dB)"
|
||||
},
|
||||
{
|
||||
"name": "Anschlüsse",
|
||||
"description": "Anschlüsse"
|
||||
},
|
||||
{
|
||||
"name": "Ausgangsimpedanz (Ω)",
|
||||
"description": "Ausgangsimpedanz (Ω)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mechanical",
|
||||
"description": "All mechanical properties",
|
||||
"property_types":[
|
||||
{
|
||||
"name": "Abmessungen (mm)",
|
||||
"description": "All mechanical properties"
|
||||
},
|
||||
{
|
||||
"name": "Gewicht (kg)",
|
||||
"description": "All mechanical properties"
|
||||
},
|
||||
{
|
||||
"name": "Kapazität (kg)",
|
||||
"description": "All mechanical properties"
|
||||
},
|
||||
{
|
||||
"name": "Programms/Features",
|
||||
"description": "All mechanical properties"
|
||||
},
|
||||
{
|
||||
"name": "Wasserverbrauch pro Zyklus (L)",
|
||||
"description": "All mechanical properties"
|
||||
},
|
||||
{
|
||||
"name": "Material Innenraum",
|
||||
"description": "All mechanical properties"
|
||||
} {
|
||||
"name": "Kapazität/Volumen (L)",
|
||||
"description": "All mechanical properties"
|
||||
},
|
||||
{
|
||||
"name": "Schleuderdrehzahl (U/min)",
|
||||
"description": "All mechanical properties"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "other",
|
||||
"description": "All other properties",
|
||||
"property_types":[
|
||||
{
|
||||
"name": "Preis (USD)",
|
||||
"description": "All other properties"
|
||||
},
|
||||
{
|
||||
"name": "Zusatzfunktionen",
|
||||
"description": "All other properties"
|
||||
}, {
|
||||
"name": "Bedienungsart",
|
||||
"description": "All other properties"
|
||||
}, {
|
||||
"name": "Energieeffizienzklasse",
|
||||
"description": "All other properties"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}]
|
||||
[
|
||||
{
|
||||
"name": "X-CPQ",
|
||||
"description": "Property Type Group for X-CPQ",
|
||||
"property_types_Groups": [
|
||||
{
|
||||
"name": "electrical",
|
||||
"description": "All electrical property types",
|
||||
"property_types": [
|
||||
{
|
||||
"name": "Spannungsversorgung (V)",
|
||||
"description": "Spannungsversorgung (V)",
|
||||
"property": {
|
||||
"name": "Spannungsversorgung (V)",
|
||||
"description": "Spannungsversorgung (V)",
|
||||
"values": [
|
||||
{ "value": "220" },
|
||||
{ "value": "230" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Leistung (W)",
|
||||
"description": "Leistung",
|
||||
"property": {
|
||||
"name": "Leistung (W)",
|
||||
"description": "Leistung",
|
||||
"values": [
|
||||
{ "value": "0" },
|
||||
{ "value": "140" },
|
||||
{ "value": "130" },
|
||||
{ "value": "120" },
|
||||
{ "value": "110" },
|
||||
{ "value": "100" },
|
||||
{ "value": "90" },
|
||||
{ "value": "80" },
|
||||
{ "value": "70" },
|
||||
{ "value": "60" },
|
||||
{ "value": "50" },
|
||||
{ "value": "28" },
|
||||
{ "value": "26" },
|
||||
{ "value": "24" },
|
||||
{ "value": "22" },
|
||||
{ "value": "20" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Eingangsimpedanz (Ω)",
|
||||
"description": "Wiederstand der Eingangsimpedanz",
|
||||
"property": {
|
||||
"name": "Eingangsimpedanz (Ω)",
|
||||
"description": "Wiederstand der Eingangsimpedanz",
|
||||
"values": [
|
||||
{ "value": "10" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Frequenzbereich (Hz‑kHz)",
|
||||
"description": "Frequenzbereich (Hz‑kHz)",
|
||||
"property": {
|
||||
"name": "Frequenzbereich (Hz‑kHz)",
|
||||
"description": "Frequenzbereich (Hz‑kHz)",
|
||||
"values": [
|
||||
{ "value": "87‑108" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Signal‑Rausch‑Verhältnis (dB)",
|
||||
"description": "Signal‑Rausch‑Verhältnis (dB)",
|
||||
"property": {
|
||||
"name": "Signal‑Rausch‑Verhältnis (dB)",
|
||||
"description": "Signal‑Rausch‑Verhältnis (dB)",
|
||||
"values": [
|
||||
{ "value": "48" },
|
||||
{ "value": "46" },
|
||||
{ "value": "47" },
|
||||
{ "value": "45" },
|
||||
{ "value": "49" },
|
||||
{ "value": "44" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Anschlüsse",
|
||||
"description": "Anschlüsse",
|
||||
"property": {
|
||||
"name": "Anschlüsse",
|
||||
"description": "Anschlüsse",
|
||||
"values": [
|
||||
{ "value": "UKW+Bluetooth+DL" },
|
||||
{ "value": "UKW+Wi‑Fi+DL" },
|
||||
{ "value": "UKW+DL+Bluetooth" },
|
||||
{ "value": "UKW+Bluetooth+Wi‑Fi" },
|
||||
{ "value": "UKW+Wi‑Fi+DL" },
|
||||
{ "value": "UKW+Wi‑Fi" },
|
||||
{ "value": "UKW+Bluetooth" },
|
||||
{ "value": "UKW+DL" },
|
||||
{ "value": "UKW" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Ausgangsimpedanz (Ω)",
|
||||
"description": "Ausgangsimpedanz (Ω)",
|
||||
"property": {
|
||||
"name": "Ausgangsimpedanz (Ω)",
|
||||
"description": "Ausgangsimpedanz (Ω)",
|
||||
"values": [
|
||||
{ "value": "75" }
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "mechanical",
|
||||
"description": "All mechanical properties",
|
||||
"property_types": [
|
||||
{
|
||||
"name": "Abmessungen (mm)",
|
||||
"description": "All mechanical properties",
|
||||
"property": {
|
||||
"name": "Abmessungen (mm)",
|
||||
"description": "All mechanical properties",
|
||||
"values": [
|
||||
{ "value": "158x88x33" },
|
||||
{ "value": "310x210x110" },
|
||||
{ "value": "160x90x35" },
|
||||
{ "value": "170x100x42" },
|
||||
{ "value": "150x80x30" },
|
||||
{ "value": "155x85x32" },
|
||||
{ "value": "165x95x38" },
|
||||
{ "value": "305x205x105" },
|
||||
{ "value": "172x102x44" },
|
||||
{ "value": "340x240x140" },
|
||||
{ "value": "420x320x140" },
|
||||
{ "value": "162x92x36" },
|
||||
{ "value": "300x200x100" },
|
||||
{ "value": "168x98x40" },
|
||||
{ "value": "315x215x115" },
|
||||
{ "value": "325x225x125" },
|
||||
{ "value": "415x315x135" },
|
||||
{ "value": "320x220x120" },
|
||||
{ "value": "335x235x135" },
|
||||
{ "value": "330x230x130" },
|
||||
{ "value": "400x300x120" },
|
||||
{ "value": "405x305x125" },
|
||||
{ "value": "345x245x145" },
|
||||
{ "value": "295x245x135" },
|
||||
{ "value": "410x310x130" },
|
||||
{ "value": "290x240x130" },
|
||||
{ "value": "285x235x125" },
|
||||
{ "value": "280x230x120" },
|
||||
{ "value": "275x225x115" },
|
||||
{ "value": "270x220x110" },
|
||||
{ "value": "265x215x105" },
|
||||
{ "value": "255x205x95" },
|
||||
{ "value": "260x210x100" },
|
||||
{ "value": "250x200x90" },
|
||||
{ "value": "445x345x165" },
|
||||
{ "value": "440x340x160" },
|
||||
{ "value": "435x335x155" },
|
||||
{ "value": "430x330x150" },
|
||||
{ "value": "425x325x145" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Gewicht (kg)",
|
||||
"description": "All mechanical properties",
|
||||
"property": {
|
||||
"name": "Gewicht (kg)",
|
||||
"description": "All mechanical properties",
|
||||
"values": [
|
||||
{ "value": "3" },
|
||||
{ "value": "6" },
|
||||
{ "value": "4" },
|
||||
{ "value": "2" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Kapazität (kg)",
|
||||
"description": "All mechanical properties",
|
||||
"property": {
|
||||
"name": "Kapazität (kg)",
|
||||
"description": "All mechanical properties",
|
||||
"values": [
|
||||
{ "value": "0" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Programms/Features",
|
||||
"description": "All mechanical properties",
|
||||
"property": {
|
||||
"name": "Programms/Features",
|
||||
"description": "All mechanical properties",
|
||||
"values": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Wasserverbrauch pro Zyklus (L)",
|
||||
"description": "All mechanical properties",
|
||||
"property": {
|
||||
"name": "Wasserverbrauch pro Zyklus (L)",
|
||||
"description": "All mechanical properties",
|
||||
"values": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Material Innenraum",
|
||||
"description": "All mechanical properties",
|
||||
"property": {
|
||||
"name": "Material Innenraum",
|
||||
"description": "All mechanical properties",
|
||||
"values": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Kapazität/Volumen (L)",
|
||||
"description": "All mechanical properties",
|
||||
"property": {
|
||||
"name": "Kapazität/Volumen (L)",
|
||||
"description": "All mechanical properties",
|
||||
"values": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Schleuderdrehzahl (U/min)",
|
||||
"description": "All mechanical properties",
|
||||
"property": {
|
||||
"name": "Schleuderdrehzahl (U/min)",
|
||||
"description": "All mechanical properties",
|
||||
"values": []
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "other",
|
||||
"description": "All other properties",
|
||||
"property_types": [
|
||||
{
|
||||
"name": "Preis (USD)",
|
||||
"description": "All other properties",
|
||||
"property": {
|
||||
"name": "Preis (USD)",
|
||||
"description": "All other properties",
|
||||
"values": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Zusatzfunktionen",
|
||||
"description": "All other properties",
|
||||
"property": {
|
||||
"name": "Zusatzfunktionen",
|
||||
"description": "All other properties",
|
||||
"values": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Bedienungsart",
|
||||
"description": "All other properties",
|
||||
"property": {
|
||||
"name": "Bedienungsart",
|
||||
"description": "All other properties",
|
||||
"values": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Energieeffizienzklasse",
|
||||
"description": "All other properties",
|
||||
"property": {
|
||||
"name": "Energieeffizienzklasse",
|
||||
"description": "All other properties",
|
||||
"values": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -1,13 +1,25 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"xcpq_editor/internal/models"
|
||||
"xcpq_editor/internal/services"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func ImportHandler_PropertyTypesGroup(ctx *gin.Context) {
|
||||
type ImportHandler struct {
|
||||
importService *services.Import_Service
|
||||
}
|
||||
|
||||
func NewImportHandler(i *services.Import_Service) *ImportHandler {
|
||||
return &ImportHandler{
|
||||
importService: i,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *ImportHandler) ImportPropertyTypeGroups(ctx *gin.Context) {
|
||||
// Handle the import request here
|
||||
|
||||
var importData []models.Property_Types_Group
|
||||
@@ -16,6 +28,16 @@ func ImportHandler_PropertyTypesGroup(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
for _, item := range importData {
|
||||
log.Println("Importing property types group with ID:", item.Id)
|
||||
log.Println("Anzahl Sub-Groups:", len(item.Property_Types_Groups))
|
||||
err := h.importService.ImportPropertyTypesData(&item, nil)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
"message": "Import successful",
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package models
|
||||
|
||||
type Property struct {
|
||||
Id int `json:"id"`
|
||||
Id int `json:"id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Image_Url string `json:"image_url,omitempty"`
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package models
|
||||
|
||||
type Property_Type struct {
|
||||
Id int `json:"id"`
|
||||
Id int `json:"id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Image_Url string `json:"image_url,omitempty"`
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package models
|
||||
|
||||
type Property_Types_Group struct {
|
||||
Id int `json:"id"`
|
||||
Id int `json:"id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Image_Url string `json:"image_url,omitempty"`
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package models
|
||||
|
||||
type Value struct {
|
||||
Id int `json:"id"`
|
||||
Id int `json:"id,omitempty"`
|
||||
Value string `json:"value"`
|
||||
Image_Url string `json:"image_url,omitempty"`
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package repositories
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"xcpq_editor/internal/models"
|
||||
)
|
||||
|
||||
@@ -13,7 +14,7 @@ type Import_Repository struct {
|
||||
pr *Property_Repository
|
||||
}
|
||||
|
||||
func NewImport_Repository(db *sql.DB, vr *Value_Repository, pt *Property_Type_Repository, ptg *Property_Types_Group_Repository, pr *Property_Repository) *Import_Repository {
|
||||
func NewImportRepository(db *sql.DB, vr *Value_Repository, pt *Property_Type_Repository, ptg *Property_Types_Group_Repository, pr *Property_Repository) *Import_Repository {
|
||||
return &Import_Repository{
|
||||
db: db,
|
||||
vr: vr,
|
||||
@@ -34,14 +35,17 @@ func (r *Import_Repository) ImportPropertyTypesData(newGroup *models.Property_Ty
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Println("Created new property types group with ID:", group.Id)
|
||||
newGroup.Id = group.Id
|
||||
for _, childPropertyType := range newGroup.Property_Types {
|
||||
log.Println("Creating new property type with ID:", childPropertyType.Id)
|
||||
_, err := r.pt.CreatePropertyType(&childPropertyType, newGroup, &childPropertyType.Property)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, childGroup := range newGroup.Property_Types_Groups {
|
||||
log.Println("Importing child property types group with ID:", childGroup.Id)
|
||||
err := r.ImportPropertyTypesData(&childGroup, newGroup)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -45,8 +45,8 @@ func (pr *Property_Repository) CreateProperty(
|
||||
parent_property_id = 0
|
||||
}
|
||||
|
||||
query := `INSERT INTO properties (name, description, parent_property_id, property_type_id, product_id, image_url) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id`
|
||||
err := pr.db.QueryRow(query, property.Name, property.Description, parent_property_id, property_type_id, product_id, property.image_url).Scan(&property.Id)
|
||||
query := `INSERT INTO properties.properties (name, description, parent_property_id, property_type_id, products_id, image_url) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id`
|
||||
err := pr.db.QueryRow(query, property.Name, property.Description, parent_property_id, property_type_id, product_id, property.Image_Url).Scan(&property.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -70,10 +70,10 @@ func (pr *Property_Repository) CreateProperty(
|
||||
|
||||
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, image_url FROM properties WHERE id = $1`
|
||||
query := `SELECT id, name, description, parent_property_id, image_url FROM properties.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, &property.image_url)
|
||||
err := pr.db.QueryRow(query, id).Scan(&property.Id, &property.Name, &property.Description, &parent_property_id, &property.Image_Url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -103,8 +103,8 @@ func (pr *Property_Repository) GetPropertyById(id int) (*models.Property, error)
|
||||
|
||||
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, image_url=$3 WHERE id=$4`
|
||||
_, err := pr.db.Exec(query, property.Name, property.Description, property.image_url, property.Id)
|
||||
query := `UPDATE properties.properties SET name=$1, description=$2, image_url=$3 WHERE id=$4`
|
||||
_, err := pr.db.Exec(query, property.Name, property.Description, property.Image_Url, property.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ func (pr *Property_Repository) DeleteProperty(id int) error {
|
||||
return err
|
||||
}
|
||||
|
||||
query := `DELETE FROM properties WHERE id=$1`
|
||||
query := `DELETE FROM properties.properties WHERE id=$1`
|
||||
_, err = pr.db.Exec(query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ func (ptr *Property_Type_Repository) CreatePropertyType(
|
||||
} else {
|
||||
property_type_group_id = 0
|
||||
}
|
||||
query := `INSERT INTO property_types (name, description, property_type_group_id, image_url) VALUES ($1, $2, $3, $4) RETURNING id`
|
||||
err := ptr.db.QueryRow(query, property_type.Name, property_type.Description, property_type_group_id, property_type.image_url).Scan(&property_type.Id)
|
||||
query := `INSERT INTO properties.property_types (name, description, property_types_groups_id, image_url) VALUES ($1, $2, $3, $4) RETURNING id`
|
||||
err := ptr.db.QueryRow(query, property_type.Name, property_type.Description, property_type_group_id, property_type.Image_Url).Scan(&property_type.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -50,9 +50,9 @@ func (ptr *Property_Type_Repository) CreatePropertyType(
|
||||
|
||||
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, image_url FROM property_types WHERE id = $1"
|
||||
query := "SELECT id, name, description, image_url FROM properties.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, &property_type.image_url)
|
||||
err := ptr.db.QueryRow(query, id).Scan(&property_type.Id, &property_type.Name, &property_type.Description, &property_type.Image_Url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -63,14 +63,14 @@ func (ptr *Property_Type_Repository) GetPropertyTypeById(id int) (*models.Proper
|
||||
|
||||
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, image_url=$3 WHERE id=$4`
|
||||
_, err := ptr.db.Exec(query, property_type.Name, property_type.Description, property_type.image_url, property_type.Id)
|
||||
query := `UPDATE properties.property_types SET name=$1, description=$2, image_url=$3 WHERE id=$4`
|
||||
_, err := ptr.db.Exec(query, property_type.Name, property_type.Description, property_type.Image_Url, property_type.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (ptr *Property_Type_Repository) DeletePropertyTypeById(id int) error {
|
||||
// Implement the logic to delete a property type from the database
|
||||
query := `DELETE FROM property_types WHERE id=$1`
|
||||
query := `DELETE FROM properties.property_types WHERE id=$1`
|
||||
_, err := ptr.db.Exec(query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ func (ptrg *Property_Types_Group_Repository) CreatePropertyTypesGroup(property_t
|
||||
parentPropertyTypeGroup.Property_Types_Groups = append(parentPropertyTypeGroup.Property_Types_Groups, *property_types_group)
|
||||
} else {
|
||||
parentId = 0 // or any other value that indicates no parent
|
||||
property_types_group.Property_Types_Groups = []models.Property_Types_Group{}
|
||||
property_types_group.Property_Types = []models.Property_Type{}
|
||||
//property_types_group.Property_Types_Groups = []models.Property_Types_Group{}
|
||||
//property_types_group.Property_Types = []models.Property_Type{}
|
||||
}
|
||||
query := `INSERT INTO property_types_groups (name, description, image_url, parent_property_type_group) VALUES ($1, $2, $3, $4) RETURNING id`
|
||||
query := `INSERT INTO properties.property_types_groups (name, description, image_url, parent_property_type_group_id) VALUES ($1, $2, $3, $4) RETURNING id`
|
||||
err := ptrg.db.QueryRow(query, property_types_group.Name, property_types_group.Description, property_types_group.Image_Url, parentId).Scan(&property_types_group.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -38,7 +38,7 @@ func (ptrg *Property_Types_Group_Repository) CreatePropertyTypesGroup(property_t
|
||||
|
||||
func (ptrg *Property_Types_Group_Repository) GetPropertyTypesGroupById(id int) (*models.Property_Types_Group, error) {
|
||||
// Implement the logic to retrieve a property types group by its ID from the database
|
||||
query := "SELECT id, name, description, image_url FROM property_types_groups WHERE id = $1"
|
||||
query := "SELECT id, name, description, image_url FROM properties.property_types_groups WHERE id = $1"
|
||||
property_types_group := &models.Property_Types_Group{}
|
||||
err := ptrg.db.QueryRow(query, id).Scan(&property_types_group.Id, &property_types_group.Name, &property_types_group.Description, &property_types_group.Image_Url)
|
||||
if err != nil {
|
||||
@@ -46,7 +46,7 @@ func (ptrg *Property_Types_Group_Repository) GetPropertyTypesGroupById(id int) (
|
||||
}
|
||||
|
||||
// get all childs
|
||||
queryChilds := "SELECT id FROM property_types_groups WHERE parent_property_type_group = $1"
|
||||
queryChilds := "SELECT id FROM properties.property_types_groups WHERE parent_property_types_groups_id = $1"
|
||||
rows, err := ptrg.db.Query(queryChilds, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -92,18 +92,18 @@ func (ptrg *Property_Types_Group_Repository) GetPropertyTypesGroupById(id int) (
|
||||
|
||||
func (ptrg *Property_Types_Group_Repository) UpdatePropertyTypesGroup(property_types_group *models.Property_Types_Group) error {
|
||||
// Implement the logic to update the label/description of an existing property types group
|
||||
query := `UPDATE property_types_groups SET name=$1, description=$2, image_url=$3 WHERE id=$4`
|
||||
query := `UPDATE properties.property_types_groups SET name=$1, description=$2, image_url=$3 WHERE id=$4`
|
||||
_, err := ptrg.db.Exec(query, property_types_group.Name, property_types_group.Description, property_types_group.Image_Url, property_types_group.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (ptrg *Property_Types_Group_Repository) DeletePropertyTypesGroup(id int) error {
|
||||
// Implement the logic to delete a property types group from the database
|
||||
query := `DELETE FROM property_types_groups WHERE id=$1`
|
||||
query := `DELETE FROM properties.property_types_groups WHERE id=$1`
|
||||
_, err := ptrg.db.Exec(query, id)
|
||||
|
||||
// delete all child property types groups
|
||||
queryChilds := "SELECT id FROM property_types_groups WHERE parent_property_type_group = $1"
|
||||
queryChilds := "SELECT id FROM properties.property_types_groups WHERE parent_property_types_groups_id = $1"
|
||||
rows, err := ptrg.db.Query(queryChilds, id)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -123,7 +123,7 @@ func (ptrg *Property_Types_Group_Repository) DeletePropertyTypesGroup(id int) er
|
||||
}
|
||||
|
||||
// delete all property types in this group
|
||||
queryProperties := "SELECT id FROM property_types WHERE property_types_group = $1"
|
||||
queryProperties := "SELECT id FROM properties.property_types WHERE property_types_group = $1"
|
||||
rowsProperties, err := ptrg.db.Query(queryProperties, id)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -17,7 +17,7 @@ func NewValueRepository(db *sql.DB) *Value_Repository {
|
||||
|
||||
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, image_url) VALUES ($1, $2, $3) RETURNING id`
|
||||
query := `INSERT INTO properties.values (propertyid, value, image_url) VALUES ($1, $2, $3) RETURNING id`
|
||||
err := vr.db.QueryRow(query, propertyId, value.Value, value.Image_Url).Scan(&value.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -27,21 +27,21 @@ func (vr *Value_Repository) CreateValueForPropertyId(propertyId int, value *mode
|
||||
|
||||
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`
|
||||
query := `DELETE FROM properties.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, image_url=$2 WHERE id=$3`
|
||||
query := `UPDATE properties.values SET value=$1, image_url=$2 WHERE id=$3`
|
||||
_, err := vr.db.Exec(query, value.Value, value.Image_Url, 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, image_url FROM values WHERE id = $1"
|
||||
query := "SELECT id, value, image_url FROM properties.values WHERE id = $1"
|
||||
row := vr.db.QueryRow(query, id)
|
||||
value := &models.Value{}
|
||||
err := row.Scan(&value.Id, &value.Value, &value.Image_Url)
|
||||
@@ -53,14 +53,14 @@ func (vr *Value_Repository) GetValue(id int) (*models.Value, error) {
|
||||
|
||||
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`
|
||||
query := `DELETE FROM properties.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, image_url FROM values WHERE propertyid=$1`
|
||||
query := `SELECT id, value, image_url FROM properties.values WHERE propertyid=$1`
|
||||
rows, err := vr.db.Query(query, propertyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -9,7 +9,7 @@ type Import_Service struct {
|
||||
importRepository *repositories.Import_Repository
|
||||
}
|
||||
|
||||
func NewImport_Service(importRepository *repositories.Import_Repository) *Import_Service {
|
||||
func NewImportService(importRepository *repositories.Import_Repository) *Import_Service {
|
||||
return &Import_Service{
|
||||
importRepository: importRepository,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user