aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/incoming/web/handlers
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-08-18 03:12:41 +0800
committerRunxi Yu <me@runxiyu.org>2025-08-18 03:12:41 +0800
commitf7dde29539536a67687cbeff9662a9617e077150 (patch)
treed976eb1f64062a65da4e689bd650ad84be737c52 /forged/internal/incoming/web/handlers
parentMove sql to inside forged (diff)
downloadforge-f7dde29539536a67687cbeff9662a9617e077150.tar.gz
forge-f7dde29539536a67687cbeff9662a9617e077150.tar.zst
forge-f7dde29539536a67687cbeff9662a9617e077150.zip
Make the index page work
Diffstat (limited to 'forged/internal/incoming/web/handlers')
-rw-r--r--forged/internal/incoming/web/handlers/group.go7
-rw-r--r--forged/internal/incoming/web/handlers/index.go24
-rw-r--r--forged/internal/incoming/web/handlers/not_implemented.go11
-rw-r--r--forged/internal/incoming/web/handlers/repo/handler.go15
-rw-r--r--forged/internal/incoming/web/handlers/repo/index.go8
5 files changed, 48 insertions, 17 deletions
diff --git a/forged/internal/incoming/web/handlers/group.go b/forged/internal/incoming/web/handlers/group.go
index 0c631c3..e56a3b5 100644
--- a/forged/internal/incoming/web/handlers/group.go
+++ b/forged/internal/incoming/web/handlers/group.go
@@ -12,7 +12,11 @@ type GroupHTTP struct {
r templates.Renderer
}
-func NewGroupHTTP(r templates.Renderer) *GroupHTTP { return &GroupHTTP{r: r} }
+func NewGroupHTTP(r templates.Renderer) *GroupHTTP {
+ return &GroupHTTP{
+ r: r,
+ }
+}
func (h *GroupHTTP) Index(w http.ResponseWriter, r *http.Request, _ wtypes.Vars) {
base := wtypes.Base(r)
@@ -22,4 +26,3 @@ func (h *GroupHTTP) Index(w http.ResponseWriter, r *http.Request, _ wtypes.Vars)
GroupPath: "/" + strings.Join(base.GroupPath, "/") + "/",
})
}
-
diff --git a/forged/internal/incoming/web/handlers/index.go b/forged/internal/incoming/web/handlers/index.go
index 259ca4a..22e6201 100644
--- a/forged/internal/incoming/web/handlers/index.go
+++ b/forged/internal/incoming/web/handlers/index.go
@@ -4,7 +4,9 @@ import (
"log"
"net/http"
+ "go.lindenii.runxiyu.org/forge/forged/internal/database/queries"
"go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/templates"
+ "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
)
@@ -12,13 +14,25 @@ type IndexHTTP struct {
r templates.Renderer
}
-func NewIndexHTTP(r templates.Renderer) *IndexHTTP { return &IndexHTTP{r: r} }
+func NewIndexHTTP(r templates.Renderer) *IndexHTTP {
+ return &IndexHTTP{
+ r: r,
+ }
+}
-func (h *IndexHTTP) Index(w http.ResponseWriter, _ *http.Request, _ wtypes.Vars) {
- err := h.r.Render(w, "index", struct {
- Title string
+func (h *IndexHTTP) Index(w http.ResponseWriter, r *http.Request, _ wtypes.Vars) {
+ groups, err := types.Base(r).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 *types.BaseData
+ Groups []queries.GetRootGroupsRow
}{
- Title: "Home",
+ BaseData: types.Base(r),
+ Groups: groups,
})
if err != nil {
log.Println("failed to render index page", "error", err)
diff --git a/forged/internal/incoming/web/handlers/not_implemented.go b/forged/internal/incoming/web/handlers/not_implemented.go
index 472f73b..6813c88 100644
--- a/forged/internal/incoming/web/handlers/not_implemented.go
+++ b/forged/internal/incoming/web/handlers/not_implemented.go
@@ -3,12 +3,19 @@ package handlers
import (
"net/http"
+ "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/templates"
wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
)
-type NotImplementedHTTP struct{}
+type NotImplementedHTTP struct {
+ r templates.Renderer
+}
-func NewNotImplementedHTTP() *NotImplementedHTTP { return &NotImplementedHTTP{} }
+func NewNotImplementedHTTP(r templates.Renderer) *NotImplementedHTTP {
+ return &NotImplementedHTTP{
+ r: r,
+ }
+}
func (h *NotImplementedHTTP) Handle(w http.ResponseWriter, _ *http.Request, _ wtypes.Vars) {
http.Error(w, "not implemented", http.StatusNotImplemented)
diff --git a/forged/internal/incoming/web/handlers/repo/handler.go b/forged/internal/incoming/web/handlers/repo/handler.go
new file mode 100644
index 0000000..2881d7d
--- /dev/null
+++ b/forged/internal/incoming/web/handlers/repo/handler.go
@@ -0,0 +1,15 @@
+package repo
+
+import (
+ "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/templates"
+)
+
+type HTTP struct {
+ r templates.Renderer
+}
+
+func NewHTTP(r templates.Renderer) *HTTP {
+ return &HTTP{
+ r: r,
+ }
+}
diff --git a/forged/internal/incoming/web/handlers/repo/index.go b/forged/internal/incoming/web/handlers/repo/index.go
index dd1382f..1a804b2 100644
--- a/forged/internal/incoming/web/handlers/repo/index.go
+++ b/forged/internal/incoming/web/handlers/repo/index.go
@@ -4,16 +4,9 @@ import (
"net/http"
"strings"
- "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/templates"
wtypes "go.lindenii.runxiyu.org/forge/forged/internal/incoming/web/types"
)
-type HTTP struct {
- r templates.Renderer
-}
-
-func NewHTTP(r templates.Renderer) *HTTP { return &HTTP{r: r} }
-
func (h *HTTP) Index(w http.ResponseWriter, r *http.Request, v wtypes.Vars) {
base := wtypes.Base(r)
repo := v["repo"]
@@ -25,4 +18,3 @@ func (h *HTTP) Index(w http.ResponseWriter, r *http.Request, v wtypes.Vars) {
Repo: repo,
})
}
-