Add guest count API

This commit is contained in:
Christoph Hagen 2022-01-10 23:45:34 +01:00
parent 7d49e8a7ed
commit 4622ad8d59
2 changed files with 14 additions and 7 deletions

View File

@ -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)

View File

@ -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