$poll->id,
"title" => $poll->title,
"creation_date" => $poll->creation_date,
"options" => $poll->options,
];
}
Flight::route("POST /polls", function () {
$request = Flight::request();
if ($request->type === "application/json")
{
$request_json = $request->data;
$poll = Poll::create_poll($request_json);
if ($poll)
Flight::json(format_poll($poll), 206);
else
Flight::halt(403, "
403 Forbidden
Invalid data.
");
}
else
Flight::halt(403, "403 Forbidden
Invalid Content-Type.
");
});
Flight::route("GET /polls/@id:[a-fA-F0-9]+", function ($id) {
$poll = Poll::load_poll($id);
if ($poll)
{
if (Flight::request()->type === "application/json")
Flight::json(format_poll($poll));
else
{
Flight::render("poll", ["poll" => $poll], "body_content");
Flight::render("layout");
}
}
else
Flight::notFound();
});
Flight::route("/", function () {
global $VERLAINE;
Flight::render("home", ["app_url" => $VERLAINE["app_url"]], "body_content");
Flight::render("layout");
});
Flight::start();