diff --git a/xcpq/buildtime/xcpq_editor/cmd/server/httpServer.go b/xcpq/buildtime/xcpq_editor/cmd/server/httpServer.go index 3dbb553c8..882a10f14 100644 --- a/xcpq/buildtime/xcpq_editor/cmd/server/httpServer.go +++ b/xcpq/buildtime/xcpq_editor/cmd/server/httpServer.go @@ -2,9 +2,9 @@ package server import ( "database/sql" - "html/template" "log" "net/http" + "xcpq_editor/internal/handlers" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" @@ -31,7 +31,13 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer { // static content router.Static("/static", "../static") - router.GET("/", home) + router.GET("/", handlers.Home) + router.GET("/properties", handlers.PropertiesHandler) + /* + router.GET("/products", handlers.ProductsHandler) + router.GET("/conditions", handlers.ConditionsHandler) + router.GET("/translations", handlers.TranslationsHandler) + */ router.GET("/test", Test) @@ -55,38 +61,3 @@ func Test(ctx *gin.Context) { "message": "Test", }) } - -func home(ctx *gin.Context) { - - /* load templates */ - - tmpl, err := template.ParseFiles( - "../templates/pages/index.html", - "../templates/layouts/navbar.html", - "../templates/layouts/properties.html", - "../templates/layouts/footer.html") - - if err != nil { - ctx.JSON(http.StatusInternalServerError, gin.H{ - "error": err.Error(), - }) - return - } - - renderTemplate(ctx, tmpl, nil) -} - -func renderTemplate(ctx *gin.Context, tmpl *template.Template, data interface{}) { - if tmpl == nil { - ctx.JSON(http.StatusInternalServerError, gin.H{ - "error": "template is nil", - }) - return - } - err := tmpl.Execute(ctx.Writer, data) - if err != nil { - ctx.JSON(http.StatusInternalServerError, gin.H{ - "error": err.Error(), - }) - } -} diff --git a/xcpq/buildtime/xcpq_editor/internal/.ignore b/xcpq/buildtime/xcpq_editor/internal/.ignore deleted file mode 100644 index e69de29bb..000000000 diff --git a/xcpq/buildtime/xcpq_editor/internal/handlers/.ignore b/xcpq/buildtime/xcpq_editor/internal/handlers/.ignore deleted file mode 100644 index e69de29bb..000000000 diff --git a/xcpq/buildtime/xcpq_editor/internal/handlers/main_handler.go b/xcpq/buildtime/xcpq_editor/internal/handlers/main_handler.go new file mode 100644 index 000000000..d58bcc2c2 --- /dev/null +++ b/xcpq/buildtime/xcpq_editor/internal/handlers/main_handler.go @@ -0,0 +1,48 @@ +package handlers + +import ( + "html/template" + "net/http" + + "github.com/gin-gonic/gin" +) + +func Home(ctx *gin.Context) { + tmpl, err := template.ParseFiles( + "../templates/pages/index.html", + "../templates/layouts/navbar.html", + "../templates/layouts/properties.html", + "../templates/layouts/footer.html") + + if err != nil { + ctx.JSON(http.StatusInternalServerError, gin.H{ + "error": err.Error(), + }) + return + } + + err = tmpl.Execute(ctx.Writer, nil) + if err != nil { + ctx.JSON(http.StatusInternalServerError, gin.H{ + "error": err.Error(), + }) + } +} + +func PropertiesHandler(ctx *gin.Context) { + ptmpl, err := template.ParseFiles( + "../templates/layouts/properties.html") + if err != nil { + ctx.JSON(http.StatusInternalServerError, gin.H{ + "error": err.Error(), + }) + return + } + + err = ptmpl.Execute(ctx.Writer, nil) + if err != nil { + ctx.JSON(http.StatusInternalServerError, gin.H{ + "error": err.Error(), + }) + } +} diff --git a/xcpq/buildtime/xcpq_editor/internal/templates/.ignore b/xcpq/buildtime/xcpq_editor/internal/templates/.ignore deleted file mode 100644 index e69de29bb..000000000 diff --git a/xcpq/buildtime/xcpq_editor/templates/layouts/navbar.html b/xcpq/buildtime/xcpq_editor/templates/layouts/navbar.html index cfa09094f..72402e985 100644 --- a/xcpq/buildtime/xcpq_editor/templates/layouts/navbar.html +++ b/xcpq/buildtime/xcpq_editor/templates/layouts/navbar.html @@ -6,10 +6,10 @@ diff --git a/xcpq/buildtime/xcpq_editor/templates/layouts/properties.html b/xcpq/buildtime/xcpq_editor/templates/layouts/properties.html index 036a9392f..162074ccb 100644 --- a/xcpq/buildtime/xcpq_editor/templates/layouts/properties.html +++ b/xcpq/buildtime/xcpq_editor/templates/layouts/properties.html @@ -1,4 +1,4 @@ -{{define "properties"}} +