FestivalServer/Sources/App/routes.swift

35 lines
787 B
Swift
Raw Normal View History

2021-10-02 21:45:32 +02:00
import Vapor
2021-11-11 08:58:36 +01:00
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)
}
}
2021-10-02 21:45:32 +02:00
func routes(_ app: Application) throws {
app.get { req in
return "It works!"
}
2021-11-11 08:58:36 +01:00
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)
2021-10-02 21:45:32 +02:00
}
}