From a0786860e274491dbcecb9cd8604e1f92f2c2059 Mon Sep 17 00:00:00 2001 From: collin Date: Mon, 30 Jun 2025 12:37:33 +0200 Subject: [PATCH] adding "admin" section to see all rsvps --- client/rsvps_list.html | 12 ++++++++++++ client/rsvps_list.js | 13 +++++++++++++ controller.go | 10 ++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 client/rsvps_list.html create mode 100644 client/rsvps_list.js diff --git a/client/rsvps_list.html b/client/rsvps_list.html new file mode 100644 index 0000000..c1c0791 --- /dev/null +++ b/client/rsvps_list.html @@ -0,0 +1,12 @@ + + + + + + +

Collin and Lucy's Wedding

+
+
+ + + \ No newline at end of file diff --git a/client/rsvps_list.js b/client/rsvps_list.js new file mode 100644 index 0000000..93aeae6 --- /dev/null +++ b/client/rsvps_list.js @@ -0,0 +1,13 @@ +function createRsvpEntry(rsvp) { + +} + +async function getRsvps() { + // token is test:test for now + const resp = await fetch('/api/rsvps', { headers: { 'Authorization': 'Basic dGVzdDp0ZXN0'} }) + JSON.parse(resp.body) +} + +window.onload = async function () { + await getRsvps(); +}; \ No newline at end of file diff --git a/controller.go b/controller.go index eb6efac..d28fd7a 100644 --- a/controller.go +++ b/controller.go @@ -70,7 +70,7 @@ func isAuthorized(r *http.Request) bool { return false } - return auth == token + return auth == fmt.Sprintf("Basic %s", token) } func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -86,12 +86,18 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { case r.Method == "GET" && r.URL.Path == "/rsvp_confirmed": getStaticFile("./client/rsvp_confirmed.html", "text/html", w) + case r.Method == "GET" && r.URL.Path == "/rsvps_list": + getStaticFile("./client/rsvps_list.html", "text/html", w) + case r.Method == "GET" && r.URL.Path == "/index.js": getStaticFile("./client/index.js", "text/javascript", w) case r.Method == "GET" && r.URL.Path == "/rsvp.js": getStaticFile("./client/rsvp.js", "text/javascript", w) + case r.Method == "GET" && r.URL.Path == "/rsvps_list.js": + getStaticFile("./client/rsvps_list.js", "text/javascript", w) + case r.Method == "GET" && r.URL.Path == "/style.css": getStaticFile("./client/style.css", "text/css", w) @@ -121,7 +127,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } attending := r.Form.Get("attending") == "true" - partySize, err := strconv.ParseInt(r.Form.Get("party-size"), 10, 1) + partySize, err := strconv.ParseInt(r.Form.Get("party-size"), 10, 64) if err != nil { fmt.Println(err)