FestivalServer/Sources/App/routes.swift
2022-01-10 23:45:34 +01:00

32 lines
757 B
Swift
Executable File

import Vapor
private func register(_ req: Request, isAttending: Bool) -> String {
guard let name = req.body.string?.trimmingCharacters(in: .whitespacesAndNewlines) else {
return "No Name"
}
if isAttending {
return add(guest: name)
} else {
return remove(guest: name)
}
}
func routes(_ app: Application) throws {
app.get("festival", "api", "ping") { req in
return "It works!"
}
app.get("festival", "api", "count") { req in
return "\(guestCount())"
}
app.post("festival", "api", "register") { req -> String in
register(req, isAttending: true)
}
app.post("festival", "api", "decline") { req -> String in
register(req, isAttending: false)
}
}