aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-08-18 05:10:14 +0800
committerRunxi Yu <me@runxiyu.org>2025-08-18 05:10:14 +0800
commitdd0017446dcd605b3670784336d38c1083895abe (patch)
treed9882611f6c38560c2490ef918ccfa46f09380c4
parentMake logging in work (diff)
downloadforge-dd0017446dcd605b3670784336d38c1083895abe.tar.gz
forge-dd0017446dcd605b3670784336d38c1083895abe.tar.zst
forge-dd0017446dcd605b3670784336d38c1083895abe.zip
Start doing the group index page...HEADmaster
-rw-r--r--forged/internal/incoming/web/handlers/group.go36
-rw-r--r--forged/sql/queries/groups.sql6
-rw-r--r--forged/templates/_group_view.tmpl8
-rw-r--r--forged/templates/group.tmpl8
4 files changed, 46 insertions, 12 deletions
diff --git a/forged/internal/incoming/web/handlers/group.go b/forged/internal/incoming/web/handlers/group.go
index e56a3b5..3551ab1 100644
--- a/forged/internal/incoming/web/handlers/group.go
+++ b/forged/internal/incoming/web/handlers/group.go
@@ -1,9 +1,10 @@
package handlers
import (
+ "log"
"net/http"
- "strings"
+ "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"
)
@@ -20,9 +21,36 @@ func NewGroupHTTP(r templates.Renderer) *GroupHTTP {
func (h *GroupHTTP) Index(w http.ResponseWriter, r *http.Request, _ wtypes.Vars) {
base := wtypes.Base(r)
- _ = h.r.Render(w, "group/index.html", struct {
- GroupPath string
+ p, err := base.Queries.GetGroupIDDescByPath(r.Context(), base.URLSegments)
+ if err != nil {
+ log.Println("failed to get group ID by path", "error", err)
+ http.Error(w, "Internal Server Error", http.StatusInternalServerError)
+ return
+ }
+ subgroups, err := base.Queries.GetSubgroups(r.Context(), &p.ID)
+ if err != nil {
+ log.Println("failed to get subgroups", "error", err)
+ http.Error(w, "Internal Server Error", http.StatusInternalServerError)
+ // TODO
+ }
+ repos, err := base.Queries.GetReposInGroup(r.Context(), p.ID)
+ if err != nil {
+ log.Println("failed to get repos in group", "error", err)
+ http.Error(w, "Internal Server Error", http.StatusInternalServerError)
+ // TODO
+ }
+ err = h.r.Render(w, "group", struct {
+ BaseData *wtypes.BaseData
+ Subgroups []queries.GetSubgroupsRow
+ Repos []queries.GetReposInGroupRow
+ Description string
}{
- GroupPath: "/" + strings.Join(base.GroupPath, "/") + "/",
+ BaseData: base,
+ Subgroups: subgroups,
+ Repos: repos,
+ Description: p.Description,
})
+ if err != nil {
+ log.Println("failed to render index page", "error", err)
+ }
}
diff --git a/forged/sql/queries/groups.sql b/forged/sql/queries/groups.sql
index 5b48fc4..90c9a94 100644
--- a/forged/sql/queries/groups.sql
+++ b/forged/sql/queries/groups.sql
@@ -28,3 +28,9 @@ SELECT c.id, COALESCE(g.description, '')
FROM group_path_cte c
JOIN groups g ON g.id = c.id
WHERE c.depth = cardinality($1::text[]);
+
+-- name: GetReposInGroup :many
+SELECT name, COALESCE(description, '') FROM repos WHERE group_id = $1;
+
+-- name: GetSubgroups :many
+SELECT name, COALESCE(description, '') FROM groups WHERE parent_group = $1;
diff --git a/forged/templates/_group_view.tmpl b/forged/templates/_group_view.tmpl
index 92b6639..de5d45d 100644
--- a/forged/templates/_group_view.tmpl
+++ b/forged/templates/_group_view.tmpl
@@ -3,7 +3,7 @@
SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
*/}}
{{- define "group_view" -}}
-{{- if .subgroups -}}
+{{- if .Subgroups -}}
<table class="wide">
<thead>
<tr>
@@ -15,7 +15,7 @@
</tr>
</thead>
<tbody>
- {{- range .subgroups -}}
+ {{- range .Subgroups -}}
<tr>
<td>
<a href="{{- .Name | path_escape -}}/">{{- .Name -}}</a>
@@ -28,7 +28,7 @@
</tbody>
</table>
{{- end -}}
-{{- if .repos -}}
+{{- if .Repos -}}
<table class="wide">
<thead>
<tr>
@@ -40,7 +40,7 @@
</tr>
</thead>
<tbody>
- {{- range .repos -}}
+ {{- range .Repos -}}
<tr>
<td>
<a href="-/repos/{{- .Name | path_escape -}}/">{{- .Name -}}</a>
diff --git a/forged/templates/group.tmpl b/forged/templates/group.tmpl
index 3338f9b..68a0261 100644
--- a/forged/templates/group.tmpl
+++ b/forged/templates/group.tmpl
@@ -3,19 +3,19 @@
SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
*/}}
{{- define "group" -}}
-{{- $group_path := .group_path -}}
+{{- $group_path := .BaseData.GroupPath -}}
<!DOCTYPE html>
<html lang="en">
<head>
{{- template "head_common" . -}}
- <title>{{- range $i, $s := .group_path -}}{{- $s -}}{{- if ne $i (len $group_path) -}}/{{- end -}}{{- end }} &ndash; {{ .global.forge_title -}}</title>
+ <title>{{- range $i, $s := $group_path -}}{{- $s -}}{{- if ne $i (len $group_path) -}}/{{- end -}}{{- end }} &ndash; {{ .BaseData.Global.ForgeTitle -}}</title>
</head>
<body class="group">
{{- template "header" . -}}
<main>
<div class="padding-wrapper">
- {{- if .description -}}
- <p>{{- .description -}}</p>
+ {{- if .Description -}}
+ <p>{{- .Description -}}</p>
{{- end -}}
{{- template "group_view" . -}}
</div>