Пример #1
0
    } else {
        sendResponse(400, initBody(true, "An error occurred."), null);
    }
});
$app->delete('/events/:id', 'checkToken', function ($id) use($app) {
    $db = new dbHandler();
    if ($db->deleteEvent($id)) {
        sendResponse(204, initBody(false, null), null);
    } else {
        sendResponse(400, initBody(true, "An error occurred."), null);
    }
});
$app->get('/events', function () use($app) {
    $db = new dbHandler();
    $offset = $app->request->get('offset');
    if ($result = $db->getEvents($offset)) {
        $events = array();
        while ($event = $result->fetch_assoc()) {
            array_push($events, $event);
        }
        sendResponse(200, initBody(false, null), $events);
    } else {
        sendResponse(400, initBody(true, "An error occurred."), null);
    }
});
function initBody($error, $message)
{
    $body = array();
    $body['error'] = $error;
    $body['message'] = $message;
    $body['content'] = array();