diff options
author | Runxi Yu <me@runxiyu.org> | 2025-08-12 11:01:07 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-09-26 17:25:37 +0800 |
commit | e238ccb06b05e88ec323ca95ad4600bd79743372 (patch) | |
tree | 46f82d4d0f4ec43e94dcde5677de1ba857862638 /forged/internal/incoming/web/handlers/index.go | |
parent | Remove forge-specific functions from misc (diff) | |
download | forge-master.tar.gz forge-master.tar.zst forge-master.zip |
Diffstat (limited to '')
-rw-r--r-- | forged/internal/incoming/web/handlers/index.go | 39 |
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) + } +} |