From ac956e5521b4ad1cce1f978cc1aef51e6aeb9480 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 13 Feb 2025 10:29:57 +0800 Subject: [PATCH] index: Reformat the page --- database.go | 1 - http_handle_group_index.go | 4 ++-- http_handle_index.go | 24 +++++++++++++++--------- schema.sql | 3 ++- templates/index.html.tmpl | 44 ++++++++++++++++++++++++++++++-------------- diff --git a/database.go b/database.go index cf4f4ba2eb339afdbade17e2b1088c389353bb8d..a5832113c624d778891bafe4edb107ee14631a4b 100644 --- a/database.go +++ b/database.go @@ -26,4 +26,3 @@ } return result, nil } - diff --git a/http_handle_group_index.go b/http_handle_group_index.go index 834c0da9564647922fbdc595e97574c91df0b718..c6949144306ab2e220a40057a5fc249deab4c84b 100644 --- a/http_handle_group_index.go +++ b/http_handle_group_index.go @@ -9,8 +9,8 @@ group_name := params["group_name"] names, err := query_list[string](r.Context(), "SELECT r.name FROM repos r JOIN groups g ON r.group_id = g.id WHERE g.name = $1;", group_name) if err != nil { - http.Error(w, "Error getting groups:: "+err.Error(), http.StatusInternalServerError) - return + http.Error(w, "Error getting groups:: "+err.Error(), http.StatusInternalServerError) + return } params["repos"] = names diff --git a/http_handle_index.go b/http_handle_index.go index 8066a03b151a07a7f7bae5523170e5cf8f9c14ba..e36332d701d953efe3a4f3c1cbbc565be27f7306 100644 --- a/http_handle_index.go +++ b/http_handle_index.go @@ -5,25 +5,31 @@ "net/http" ) func handle_index(w http.ResponseWriter, r *http.Request, params map[string]any) { - rows, err := database.Query(r.Context(), "SELECT name FROM groups") + rows, err := database.Query(r.Context(), "SELECT name, COALESCE(description, '') FROM groups") if err != nil { - http.Error(w, "Error querying groups: : "+err.Error(), http.StatusInternalServerError) + http.Error(w, "Error querying groups: "+err.Error(), http.StatusInternalServerError) return } defer rows.Close() - groups := []string{} + groups := []struct { + Name string + Description string + }{} for rows.Next() { - var groupName string - if err := rows.Scan(&groupName); err != nil { - http.Error(w, "Error scanning group name: : "+err.Error(), http.StatusInternalServerError) + var groupName, groupDescription string + if err := rows.Scan(&groupName, &groupDescription); err != nil { + http.Error(w, "Error scanning group: "+err.Error(), http.StatusInternalServerError) return } - groups = append(groups, groupName) + groups = append(groups, struct { + Name string + Description string + }{groupName, groupDescription}) } if err := rows.Err(); err != nil { - http.Error(w, "Error iterating over rows: : "+err.Error(), http.StatusInternalServerError) + http.Error(w, "Error iterating over rows: "+err.Error(), http.StatusInternalServerError) return } @@ -31,7 +37,7 @@ params["groups"] = groups err = templates.ExecuteTemplate(w, "index", params) if err != nil { - http.Error(w, "Error rendering template: : "+err.Error(), http.StatusInternalServerError) + http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) return } } diff --git a/schema.sql b/schema.sql index aa5e38ef506e3b99e9c396e634f192fa6b774aaf..0aaebd8cda97986f0a3c8cd08f8243e49813f935 100644 --- a/schema.sql +++ b/schema.sql @@ -1,6 +1,7 @@ CREATE TABLE groups ( id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, - name TEXT NOT NULL UNIQUE + name TEXT NOT NULL UNIQUE, + description TEXT ); CREATE TABLE repos ( diff --git a/templates/index.html.tmpl b/templates/index.html.tmpl index 50cd489741671d925b6e556fbf61fb4fb7589463..c7259487f2810f4582f0599e2c801e731677a5d5 100644 --- a/templates/index.html.tmpl +++ b/templates/index.html.tmpl @@ -8,21 +8,37 @@ {{ template "header" . }}
-

Lindenii Forge

-

- Groups -

- -

- Info -

+ + + + + + + {{- range .groups }} + + + + + {{- end }} + +
+ Groups +
+ {{ .Name }} + + {{ .Description }} +
+
+
+ + + + + + -- 2.48.1
+ Info +
SSH Public Key