From dd0017446dcd605b3670784336d38c1083895abe Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Mon, 18 Aug 2025 05:10:14 +0800 Subject: [PATCH] Start doing the group index page... --- forged/internal/incoming/web/handlers/group.go | 36 ++++++++++++++++++++++++++++++++---- forged/sql/queries/groups.sql | 6 ++++++ forged/templates/_group_view.tmpl | 8 ++++---- forged/templates/group.tmpl | 8 ++++---- diff --git a/forged/internal/incoming/web/handlers/group.go b/forged/internal/incoming/web/handlers/group.go index e56a3b53f8ea8514f94721b953e88fbed96d7ad1..3551ab18f72ea7f2cce2a6fd21c28ec0b2d5e685 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 (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 5b48fc40ceb5809e14f5bf774900d423dc23104a..90c9a941955d8f2faccf173da662842f985db953 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 92b66390e0ec1409837a48fcf7694804f26ebabd..de5d45d14f1e16eb3df0cb9950dd6b41386f2bba 100644 --- a/forged/templates/_group_view.tmpl +++ b/forged/templates/_group_view.tmpl @@ -3,7 +3,7 @@ SPDX-License-Identifier: AGPL-3.0-only SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu */}} {{- define "group_view" -}} -{{- if .subgroups -}} +{{- if .Subgroups -}} @@ -15,7 +15,7 @@ - {{- range .subgroups -}} + {{- range .Subgroups -}}
Description
{{- .Name -}} @@ -28,7 +28,7 @@ {{- end -}}
{{- end -}} -{{- if .repos -}} +{{- if .Repos -}} @@ -40,7 +40,7 @@ - {{- range .repos -}} + {{- range .Repos -}}
{{- .Name -}} diff --git a/forged/templates/group.tmpl b/forged/templates/group.tmpl index 3338f9b0c1b19ee53b60d4e5df86131b5c9a3be2..68a0261a5fb96fac3bf671d272fdb39ebba11bda 100644 --- a/forged/templates/group.tmpl +++ b/forged/templates/group.tmpl @@ -3,19 +3,19 @@ SPDX-License-Identifier: AGPL-3.0-only SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu */}} {{- define "group" -}} -{{- $group_path := .group_path -}} +{{- $group_path := .BaseData.GroupPath -}} {{- template "head_common" . -}} - {{- range $i, $s := .group_path -}}{{- $s -}}{{- if ne $i (len $group_path) -}}/{{- end -}}{{- end }} – {{ .global.forge_title -}} + {{- range $i, $s := $group_path -}}{{- $s -}}{{- if ne $i (len $group_path) -}}/{{- end -}}{{- end }} – {{ .BaseData.Global.ForgeTitle -}} {{- template "header" . -}}
- {{- if .description -}} -

{{- .description -}}

+ {{- if .Description -}} +

{{- .Description -}}

{{- end -}} {{- template "group_view" . -}}
-- 2.48.1