sourcen übernommen und wieder compilierbar gemacht.

This commit is contained in:
2026-09-21 08:04:14 +02:00
parent 4874f8c7e7
commit 7012356fc3
40 changed files with 6218 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
# 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=xcpq sslmode=disable"
##connection_string = "host=localhost port=5432 user=tsindt password=XD14ko8d dbname=xcpq sslmode=disable"
driver_name = "postgres"
################################################################
# HTTP server configuration
[http]
server_address = ":8088"
################################################################
+23
View File
@@ -0,0 +1,23 @@
package main
import (
"log"
_ "github.com/lib/pq"
"SimplyCPQ2/cmd/server"
"SimplyCPQ2/internal/config"
)
func main() {
log.Println("Starting XCPQ 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("XCPQ Editor Service Stopped")
}
+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
}
+104
View File
@@ -0,0 +1,104 @@
package server
import (
handler "SimplyCPQ2/internal/handler"
"SimplyCPQ2/internal/repositories"
"SimplyCPQ2/internal/services"
"database/sql"
"log"
"net/http"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)
type HttpServer struct {
config *viper.Viper
router *gin.Engine
dbHandler *sql.DB
importHandler *handler.ImportHandler
importRepository *repositories.ImportRepository
valueRepository *repositories.ValueRepository
propertyRepository *repositories.PropertyRepository
propertyTypeRepository *repositories.PropertyTypeRepository
propertyTypeGroupRepository *repositories.PropertyTypeGroupRepository
}
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)
propertyTypesService := services.NewPropertyTypeService(propertyTypeRepository, propertyTypeGroupRepository)
// handler initialisation:
importHandler := handler.NewImportHandler(importService)
mainHandler := handler.NewMainHandler(propertyTypesService)
propertyTypeHandler := handler.NewPropertyTypeHandler(propertyTypesService)
// Service API
router := gin.Default()
// initialize templates
//router.LoadHTMLGlob("../templates/**/*.html")
router.Use(cors.Default())
// static content
router.Static("/static", "../static")
router.GET("/", mainHandler.Home)
router.GET("/properties/rootnodes", propertyTypeHandler.GetRootPropertyTypeGroups)
//router.GET("/properties", handler.PropertiesHandler)
/* old routes
// properties
router.GET("/properties/:id/childs", PropertyTypeHandler.GetPropertyTypesGroupDirectChildsById)
*/
/*
router.GET("/products", handlers.ProductsHandler)
router.GET("/conditions", handlers.ConditionsHandler)
router.GET("/translations", handlers.TranslationsHandler)
*/
// import
router.POST("/importPropertyTypes", importHandler.ImportPropertyTypeGroups)
// test endpoint
router.GET("/test", Test)
// server
return HttpServer{
config: config,
router: router,
dbHandler: dbHandler,
importHandler: importHandler,
importRepository: importRepository,
valueRepository: valueRepository,
propertyRepository: propertyRepository,
propertyTypeRepository: propertyTypeRepository,
propertyTypeGroupRepository: propertyTypeGroupRepository,
}
}
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",
})
}
+1
View File
@@ -0,0 +1 @@
exit status 1
Binary file not shown.