From 4622ad8d59b48fe98478e3e4d0f4b22f8867b34b Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Mon, 10 Jan 2022 23:45:34 +0100 Subject: [PATCH] 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