aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/incoming/web/handlers/index.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-08-12 11:01:07 +0800
committerRunxi Yu <me@runxiyu.org>2025-09-26 17:25:37 +0800
commite238ccb06b05e88ec323ca95ad4600bd79743372 (patch)
tree46f82d4d0f4ec43e94dcde5677de1ba857862638 /forged/internal/incoming/web/handlers/index.go
parentRemove forge-specific functions from misc (diff)
downloadforge-e238ccb06b05e88ec323ca95ad4600bd79743372.tar.gz
forge-e238ccb06b05e88ec323ca95ad4600bd79743372.tar.zst
forge-e238ccb06b05e88ec323ca95ad4600bd79743372.zip
RefactorHEADmaster
Diffstat (limited to 'forged/internal/incoming/web/handlers/index.go')
-rw-r--r--forged/internal/incoming/web/handlers/index.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/forged/internal/incoming/web/handlers/index.go b/forged/internal/incoming/web/handlers/index.go
new file mode 100644
index 0000000..a758b07
--- /dev/null
+++ b/forged/internal/incoming/web/handlers/index.go
@@ -0,0 +1,39 @@
+package handlers
+
+import (
+ "log"
+ "net/http"
+
+ "go.lindenii.runxiyu.org/forge/forged/internal/database/queries"
+ "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/templates"
+ wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
+)
+
+type IndexHTTP struct {
+ r templates.Renderer
+}
+
+func NewIndexHTTP(r templates.Renderer) *IndexHTTP {
+ return &IndexHTTP{
+ r: r,
+ }
+}
+
+func (h *IndexHTTP) Index(w http.ResponseWriter, r *http.Request, _ wtypes.Vars) {
+ groups, err := wtypes.Base(r).Global.Queries.GetRootGroups(r.Context())
+ if err != nil {
+ http.Error(w, "failed to get root groups", http.StatusInternalServerError)
+ log.Println("failed to get root groups", "error", err)
+ return
+ }
+ err = h.r.Render(w, "index", struct {
+ BaseData *wtypes.BaseData
+ Groups []queries.GetRootGroupsRow
+ }{
+ BaseData: wtypes.Base(r),
+ Groups: groups,
+ })
+ if err != nil {
+ log.Println("failed to render index page", "error", err)
+ }
+}