Made all the templating work with gin instead

This commit is contained in:
2025-07-28 13:50:10 +01:00
parent 0d373d1990
commit 8b257a3e13
25 changed files with 140 additions and 270 deletions
+15 -47
View File
@@ -1,13 +1,10 @@
package pages
import (
"expenses/config"
"expenses/expenses"
"expenses/templating"
"fmt"
"net/http"
fp "path/filepath"
"strconv"
"github.com/gin-gonic/gin"
@@ -17,75 +14,46 @@ const (
TypesPath = "/types"
)
func typesContent() (map[string]any, error) {
func typesGlobalPage(c *gin.Context) {
types, err := expenses.GetAllTypes()
if err != nil {
return nil, err
}
data := map[string]any{
"size": len(types) - 1,
"types": types,
"resource": "types",
}
return data, nil
}
func typesGlobalPage(c *gin.Context) {
cfg := config.GetInstance()
types, err := typesContent()
if err != nil {
c.Header("HX-Redirect", "/500")
ServerErrorView(c, "the server failed to get the types")
return
}
content := templating.HtmlTemplate(
fp.Join(cfg.AssetsDir, "htmx/types.html"),
types,
)
c.HTML(http.StatusOK, "terminal.html", gin.H{
c.HTML(http.StatusOK, "terminal", gin.H{
"page": "types",
"renderNavBar": true,
"content": content,
"content": "types",
"types": types,
})
}
func typePage(c *gin.Context) {
cfg := config.GetInstance()
typeID, err := strconv.Atoi(c.Param("id"))
if err != nil {
c.Redirect(404, "/404")
NotFoundView(c, "requested type doesn't exist")
return
}
typ, err := expenses.GetType(typeID)
content := templating.HtmlTemplate(
fp.Join(cfg.AssetsDir, "/htmx/type.html"),
map[string]any{
"type": typ,
},
)
if err != nil {
ServerErrorView(c, "failed to retrieve requested type")
}
c.HTML(http.StatusOK, "terminal.html", gin.H{
c.HTML(http.StatusOK, "terminal", gin.H{
"page": "type",
"renderNavBar": false,
"content": content,
"content": "type",
"type": typ,
})
}
func newTypePage(c *gin.Context) {
cfg := config.GetInstance()
content := templating.HtmlTemplate(
fp.Join(cfg.AssetsDir, "/htmx/typeNew.html"), map[string]any{},
)
c.HTML(http.StatusOK, "terminal.html", gin.H{
c.HTML(http.StatusOK, "terminal", gin.H{
"page": "typeNew",
"renderNavBar": false,
"content": content,
"content": "typeNew",
})
}