aboutsummaryrefslogtreecommitdiff
path: root/http_handle_group_index.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-06 20:29:39 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-06 20:29:39 +0800
commit649d237f9e3f9efbb0af08f5af82b776a3d81654 (patch)
tree5ce56018b221df792202f435da41931f68af436c /http_handle_group_index.go
parent*: Reformat (diff)
downloadforge-649d237f9e3f9efbb0af08f5af82b776a3d81654.tar.gz
forge-649d237f9e3f9efbb0af08f5af82b776a3d81654.tar.zst
forge-649d237f9e3f9efbb0af08f5af82b776a3d81654.zip
group/index: Add group description
Diffstat (limited to 'http_handle_group_index.go')
-rw-r--r--http_handle_group_index.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/http_handle_group_index.go b/http_handle_group_index.go
index 429532c..e3f94fd 100644
--- a/http_handle_group_index.go
+++ b/http_handle_group_index.go
@@ -16,9 +16,50 @@ func handle_group_index(w http.ResponseWriter, r *http.Request, params map[strin
var repos []name_desc_t
var subgroups []name_desc_t
var err error
+ var group_description string
group_path = params["group_path"].([]string)
+ // The group itself
+ err = database.QueryRow(r.Context(), `
+ WITH RECURSIVE group_path_cte AS (
+ SELECT
+ id,
+ parent_group,
+ name,
+ 1 AS depth
+ FROM groups
+ WHERE name = ($1::text[])[1]
+ AND parent_group IS NULL
+
+ UNION ALL
+
+ SELECT
+ g.id,
+ g.parent_group,
+ g.name,
+ group_path_cte.depth + 1
+ FROM groups g
+ JOIN group_path_cte ON g.parent_group = group_path_cte.id
+ WHERE g.name = ($1::text[])[group_path_cte.depth + 1]
+ AND group_path_cte.depth + 1 <= cardinality($1::text[])
+ )
+ SELECT COALESCE(g.description, '')
+ FROM group_path_cte c
+ JOIN groups g ON g.id = c.id
+ WHERE c.depth = cardinality($1::text[])
+ `,
+ pgtype.FlatArray[string](group_path),
+ ).Scan(&group_description)
+
+ if err == pgx.ErrNoRows {
+ http.Error(w, "Group not found", http.StatusNotFound)
+ return
+ } else if err != nil {
+ http.Error(w, "Error getting group: "+err.Error(), http.StatusInternalServerError)
+ return
+ }
+
// Repos
var rows pgx.Rows
rows, err = database.Query(r.Context(), `
@@ -122,6 +163,7 @@ func handle_group_index(w http.ResponseWriter, r *http.Request, params map[strin
params["repos"] = repos
params["subgroups"] = subgroups
+ params["description"] = group_description
fmt.Println(group_path)