From 5558d42bdbbffd6afd41553ff68db106b43f8531 Mon Sep 17 00:00:00 2001 From: miaurizius Date: Tue, 9 Jun 2026 14:44:14 +0200 Subject: [PATCH] fixed https://git.miaurizius.de/MiauRizius/MiauInv/issues/2 --- frontend/handler.go | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/frontend/handler.go b/frontend/handler.go index aecea49..84b4715 100644 --- a/frontend/handler.go +++ b/frontend/handler.go @@ -1,6 +1,7 @@ package frontend import ( + "MiauInv/storage" "html/template" "net/http" "os" @@ -53,7 +54,28 @@ func Home(w http.ResponseWriter, r *http.Request) { func Dashboard(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") - err := dashboard.ExecuteTemplate(w, "base.html", struct { + + var itemHive, projectHive, locationHive int + + err := storage.DB.QueryRow("SELECT COUNT(*) FROM items").Scan(&itemHive) + if err != nil { + http.Error(w, "Failed to count items", http.StatusInternalServerError) + return + } + + err = storage.DB.QueryRow("SELECT COUNT(*) FROM projects").Scan(&projectHive) + if err != nil { + http.Error(w, "Failed to count projects", http.StatusInternalServerError) + return + } + + err = storage.DB.QueryRow("SELECT COUNT(*) FROM locations").Scan(&locationHive) + if err != nil { + http.Error(w, "Failed to count locations", http.StatusInternalServerError) + return + } + + err = dashboard.ExecuteTemplate(w, "base.html", struct { Title string Stats struct { Items int @@ -67,9 +89,9 @@ func Dashboard(w http.ResponseWriter, r *http.Request) { Projects int Locations int }{ - Items: 1, - Projects: 1, - Locations: 3, + Items: itemHive, + Projects: projectHive, + Locations: locationHive, }, }) if err != nil {