From 1b6fc173d3ae4e62aecb6c1d81e8d59881b69a3a Mon Sep 17 00:00:00 2001 From: dylan Date: Mon, 20 Jan 2025 18:08:19 +0100 Subject: [PATCH] Add page for results --- cmd/web/handlers.go | 11 +++ cmd/web/routes.go | 1 + ui/election-results.html | 145 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 ui/election-results.html diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index a064606..8a92f77 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -39,6 +39,17 @@ func (app *application) createElectionPage(w http.ResponseWriter, r *http.Reques w.Write(content) } +func (app *application) getElectionResultsPage(w http.ResponseWriter, r *http.Request) { + content, err := ui.Files.ReadFile("election-results.html") + if err != nil { + app.serverError(w, r, err) + return + } + + w.Header().Set("Content-Type", "text/html") + w.Write(content) +} + func (app *application) getElectionPage(w http.ResponseWriter, r *http.Request) { content, err := ui.Files.ReadFile("election.html") if err != nil { diff --git a/cmd/web/routes.go b/cmd/web/routes.go index 99a42c9..9ef460d 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -24,6 +24,7 @@ func (app *application) routes() http.Handler { mux.HandleFunc("GET /", app.indexPage) mux.HandleFunc("GET /election/create", app.createElectionPage) + mux.HandleFunc("GET /election/{id}/results", app.getElectionResultsPage) mux.HandleFunc("GET /election/{id}", app.getElectionPage) api.HandlerWithOptions(app, api.StdHTTPServerOptions{ diff --git a/ui/election-results.html b/ui/election-results.html new file mode 100644 index 0000000..805989f --- /dev/null +++ b/ui/election-results.html @@ -0,0 +1,145 @@ + + + + + + Election Results - qv + + + + + +
+
+

Election Results

+ +
+

+
+ + +
+
+ + + + \ No newline at end of file