FestivalServer/Sources/App/routes.swift
2021-11-11 08:58:36 +01:00

35 lines
787 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 { req in
return "It works!"
}
app.get("festival", "api", "hello") { req in
return "It works!"
}
app.get("hello") { req in
return "It works!"
}
app.post("festival", "api", "register") { req -> String in
register(req, isAttending: true)
}
app.post("festival", "api", "decline") { req -> String in
register(req, isAttending: false)
}
}