Пример #1
0
});
$app->get('/users', function () use($app) {
    $db = new dbHandler();
    if ($result = $db->getUsers()) {
        $users = array();
        while ($user = $result->fetch_assoc()) {
            array_push($users, $user);
        }
        sendResponse(200, initBody(false, null), $users);
    } else {
        sendResponse(400, initBody(true, "An error occured."), null);
    }
});
$app->get('/users/:id/events', function ($id) use($app) {
    $db = new dbHandler();
    if ($result = $db->getUserEvents($id)) {
        $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);
    }
});
$app->post('/users/:userId/events/:eventId', 'checkToken', function ($userId, $eventId) use($app) {
    $db = new dbHandler();
    if ($db->addEvent($userId, $eventId)) {
        sendResponse(200, initBody(false, null), null);
    } else {
        sendResponse(400, initBody(true, "An error occurred."), null);