Import Serverfunktionen angelegt
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"simplycpq/models"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ImportController struct {
|
||||
importService *ImportService
|
||||
}
|
||||
|
||||
func NewImportController(i *ImportService) *ImportController {
|
||||
return &ImportController{
|
||||
importService: i,
|
||||
}
|
||||
}
|
||||
|
||||
func (ic *ImportController) ImportPropertyTypeGroups(c *gin.Context) {
|
||||
// Implement the logic for importing PropertyTypeGroups here
|
||||
var importData []models.ImportPropertyTypeGroup
|
||||
if err := c.ShouldBindJSON(&importData); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
serviceErr := ic.importService.ImportPropertyTypeGroups(importData)
|
||||
if serviceErr != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": serviceErr.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Import PropertyTypeGroups endpoint"})
|
||||
}
|
||||
|
||||
func (ic *ImportController) ImportProductGroups(c *gin.Context) {
|
||||
// Implement the logic for importing ProductGroups here
|
||||
var importData []models.ImportProductGroup
|
||||
if err := c.ShouldBindJSON(&importData); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
serviceErr := ic.importService.ImportProductGroups(importData)
|
||||
if serviceErr != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": serviceErr.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Import ProductGroups endpoint"})
|
||||
}
|
||||
|
||||
func (ic *ImportController) ImportProducts(c *gin.Context) {
|
||||
// Implement the logic for importing Products here
|
||||
var importData []models.ImportProduct
|
||||
if err := c.ShouldBindJSON(&importData); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
serviceErr := ic.importService.ImportProducts(importData)
|
||||
if serviceErr != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": serviceErr.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Import Products endpoint"})
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
{
|
||||
"label": "Simply CPQ",
|
||||
"description": "Property Type Group for Simply CPQ",
|
||||
"propertyTypeGroups": [
|
||||
{
|
||||
"label": "electrical",
|
||||
"description": "All electrical property types",
|
||||
"propertyTypes": [
|
||||
{
|
||||
"label": "Spannungsversorgung (V)",
|
||||
"description": "Spannungsversorgung (V)"
|
||||
},
|
||||
{
|
||||
"label": "Leistung (W)",
|
||||
"description": "All kitchen products"
|
||||
},
|
||||
{
|
||||
"label": "Eingangsimpedanz (Ω)",
|
||||
"description": "All kitchen products"
|
||||
},
|
||||
{
|
||||
"label": "Frequenzbereich (Hz‑kHz)",
|
||||
"description": "All kitchen products"
|
||||
},
|
||||
{
|
||||
"label": "Signal‑Rausch‑Verhältnis (dB)",
|
||||
"description": "All kitchen products"
|
||||
},
|
||||
{
|
||||
"label": "Anschlüsse",
|
||||
"description": "All kitchen products"
|
||||
},
|
||||
{
|
||||
"label": "Ausgangsimpedanz (Ω)",
|
||||
"description": "All machines products"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "mechanical",
|
||||
"description": "All mechanical properties",
|
||||
"propertyTypes":[
|
||||
{
|
||||
"label": "Abmessungen (mm)",
|
||||
"description": "All mechanical properties"
|
||||
},
|
||||
{
|
||||
"label": "Gewicht (kg)",
|
||||
"description": "All mechanical properties"
|
||||
},
|
||||
{
|
||||
"label": "Kapazität (kg)",
|
||||
"description": "All mechanical properties"
|
||||
},
|
||||
{
|
||||
"label": "Programms/Features",
|
||||
"description": "All mechanical properties"
|
||||
},
|
||||
{
|
||||
"label": "Wasserverbrauch pro Zyklus (L)",
|
||||
"description": "All mechanical properties"
|
||||
},
|
||||
{
|
||||
"label": "Schleuderdrehzahl (U/min)",
|
||||
"description": "All mechanical properties"
|
||||
}
|
||||
],
|
||||
"propertyTypeGroups": []
|
||||
},
|
||||
{
|
||||
"label": "other",
|
||||
"description": "All other properties",
|
||||
"propertyTypes":[
|
||||
{
|
||||
"label": "Preis (USD)",
|
||||
"description": "All other properties"
|
||||
},
|
||||
{
|
||||
"label": "Energieeffizienzklasse",
|
||||
"description": "All other properties"
|
||||
}
|
||||
],
|
||||
"propertyTypeGroups": []
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package models
|
||||
|
||||
type ImportPropertyTypeGroup struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
Label string `json:"label"`
|
||||
Description string `json:"description"`
|
||||
SubGroups []ImportPropertyTypeGroup `json:"subGroups,omitempty"`
|
||||
PropertyTypes []ImportPropertyType `json:"propertyTypes,omitempty"`
|
||||
}
|
||||
|
||||
type ImportPropertyType struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
Label string `json:"label"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type ImportProperty struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
Label string `json:"label"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
type ImportProductGroup struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
Label string `json:"label"`
|
||||
Description string `json:"description"`
|
||||
SubGroups []ImportProductGroup `json:"subGroups,omitempty"`
|
||||
Products []ImportProduct `json:"products,omitempty"`
|
||||
}
|
||||
|
||||
type ImportProduct struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
Label string `json:"label"`
|
||||
Description string `json:"description"`
|
||||
Properties []ImportProperty `json:"properties,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"simplycpq/models"
|
||||
)
|
||||
|
||||
type ImportRepository struct {
|
||||
db *sql.DB
|
||||
productGroupRepo *ProductGroupRepository
|
||||
productRepo *ProductRepository
|
||||
valueRepo *ValueRepository
|
||||
}
|
||||
|
||||
func NewImportRepository(db *sql.DB, productGroupRepo *ProductGroupRepository, productRepo *ProductRepository, valueRepo *ValueRepository) *ImportRepository {
|
||||
return &ImportRepository{
|
||||
db: db,
|
||||
productGroupRepo: productGroupRepo,
|
||||
productRepo: productRepo,
|
||||
valueRepo: valueRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ImportRepository) ImportPropertyTypeGroups(importData []models.ImportPropertyTypeGroup) error {
|
||||
// Implement the logic to import PropertyTypeGroups into the database
|
||||
// This is a placeholder implementation; you need to write the actual logic
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ImportRepository) ImportProductGroups(importData []models.ImportProductGroup) error {
|
||||
// Implement the logic to import ProductGroups into the database
|
||||
// This is a placeholder implementation; you need to write the actual logic
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ImportRepository) ImportProducts(importData []models.ImportProduct) error {
|
||||
// Implement the logic to import Products into the database
|
||||
// This is a placeholder implementation; you need to write the actual logic
|
||||
return nil
|
||||
}
|
||||
@@ -29,16 +29,19 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
||||
valueRepository := repositories.NewValueRepository(dbHandler)
|
||||
productGroupRepository := repositories.NewProductGroupRepository(dbHandler, valueRepository)
|
||||
productRepository := repositories.NewProductRepository(dbHandler, productGroupRepository, valueRepository)
|
||||
importRepository := repositories.NewImportRepository(dbHandler, productGroupRepository, productRepository, valueRepository)
|
||||
|
||||
// service initialisation:
|
||||
valueService := services.NewValueService(valueRepository)
|
||||
productGroupService := services.NewProductGroupService(productGroupRepository)
|
||||
productService := services.NewProductService(productRepository)
|
||||
importService := services.NewImportService(importRepository)
|
||||
|
||||
// controller initialisation:
|
||||
valueController := controller.NewValueController(valueService)
|
||||
productGroupController := controller.NewProductGroupController(productGroupService, valueService)
|
||||
productController := controller.NewProductController(productService, productGroupService, valueService)
|
||||
importController := controller.NewImportController(importService)
|
||||
|
||||
// Service API
|
||||
router := gin.Default()
|
||||
@@ -89,6 +92,11 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
||||
router.POST("/addPropertyToProductId/:productId", productController.AddPropertyToProductId) // add Property to Product by ID
|
||||
router.DELETE("/deletePropertyFromProductId/:productId", productController.DeletePropertyFromProductId) // delete Property from Product by ID
|
||||
|
||||
// Import functionality
|
||||
router.POST("/importPropertyTypeGroups", importController.ImportPropertyTypeGroups) // import PropertyTypeGroups
|
||||
router.POST("/importProductGroups", importController.ImportProductGroups) // import ProductGroups
|
||||
router.POST("/importProducts", importController.ImportProducts) // import Products
|
||||
|
||||
// server
|
||||
return HttpServer{
|
||||
config: config,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"simplycpq/models"
|
||||
"simplycpq/repositories"
|
||||
)
|
||||
|
||||
type ImportService struct {
|
||||
importRepository *repositories.ImportRepository
|
||||
}
|
||||
|
||||
func NewImportService(iRepo *repositories.ImportRepository) *ImportService {
|
||||
return &ImportService{
|
||||
importRepository: iRepo,
|
||||
}
|
||||
}
|
||||
|
||||
func (is *ImportService) ImportPropertyTypeGroups(importData []models.ImportPropertyTypeGroup) error {
|
||||
return is.importRepository.ImportPropertyTypeGroups(importData)
|
||||
}
|
||||
|
||||
func (is *ImportService) ImportProductGroups(importData []models.ImportProductGroup) error {
|
||||
return is.importRepository.ImportProductGroups(importData)
|
||||
}
|
||||
|
||||
func (is *ImportService) ImportProducts(importData []models.ImportProduct) error {
|
||||
return is.importRepository.ImportProducts(importData)
|
||||
}
|
||||
Reference in New Issue
Block a user