From 4622ad8d59b48fe98478e3e4d0f4b22f8867b34b Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Mon, 10 Jan 2022 23:45:34 +0100 Subject: [PATCH 1/3] Add guest count API --- Sources/App/configure.swift | 10 ++++++++++ Sources/App/routes.swift | 11 ++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 9bf4800..19afea9 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -16,6 +16,16 @@ private let df: DateFormatter = { return df }() +func guestCount() -> Int { + registeredGuests + .reduce([]) { $0 + $1.components(separatedBy: "+") } + .reduce([]) { $0 + $1.components(separatedBy: "-") } + .reduce([]) { $0 + $1.components(separatedBy: "und ") } + .reduce([]) { $0 + $1.components(separatedBy: "&") } + //.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } + .count +} + func add(guest: String) -> String { registeredGuests.insert(guest) diff --git a/Sources/App/routes.swift b/Sources/App/routes.swift index 98807be..375dd08 100755 --- a/Sources/App/routes.swift +++ b/Sources/App/routes.swift @@ -12,16 +12,13 @@ private func register(_ req: Request, isAttending: Bool) -> String { } func routes(_ app: Application) throws { - app.get { req in + + app.get("festival", "api", "ping") { req in return "It works!" } - app.get("festival", "api", "hello") { req in - return "It works!" - } - - app.get("hello") { req in - return "It works!" + app.get("festival", "api", "count") { req in + return "\(guestCount())" } app.post("festival", "api", "register") { req -> String in From d041600ec087b9f36dae5379868f5c51852e26a4 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Mon, 10 Jan 2022 23:50:47 +0100 Subject: [PATCH 2/3] Show guest count --- Public/assets/festival-info.js | 14 ++++++++++++++ Public/festival-info.html | 1 + 2 files changed, 15 insertions(+) diff --git a/Public/assets/festival-info.js b/Public/assets/festival-info.js index 4a8a7fa..2729246 100644 --- a/Public/assets/festival-info.js +++ b/Public/assets/festival-info.js @@ -17,3 +17,17 @@ function loadList(name, source) { txtFile.open("GET", list, true); txtFile.send(null); } + +function loadCount() { + var txtFile = new XMLHttpRequest(); + var allText = ""; + txtFile.onreadystatechange = function () { + if (txtFile.readyState === XMLHttpRequest.DONE && txtFile.status == 200) { + allText = txtFile.responseText; + } + document.getElementById("left-button").innerHTML = "Registered (" + allText + ")"; + } + var list = '/festival/api/count' + name; + txtFile.open("GET", list, true); + txtFile.send(null); +} diff --git a/Public/festival-info.html b/Public/festival-info.html index ce14c1e..edc7a94 100644 --- a/Public/festival-info.html +++ b/Public/festival-info.html @@ -49,6 +49,7 @@
Liste nicht geladen
+ From c350389e72d589b171a35b5bd6ec76a85457ace7 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Mon, 10 Jan 2022 23:58:18 +0100 Subject: [PATCH 3/3] Force script reload --- Public/festival-info.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Public/festival-info.html b/Public/festival-info.html index edc7a94..0446603 100644 --- a/Public/festival-info.html +++ b/Public/festival-info.html @@ -19,7 +19,7 @@ - +