Example #1
0
    }
    $personModel = new PersonModel($app['db']);
    if (!empty($personModel->findByName($name))) {
        throw new ValidationException("Person with name '{$name}' already exists");
    }
    $data = $personModel->create($name);
    return $app->json($data);
});
// Add user to your friends (send request)
$app->post('/api/v1/person/add/', function (Request $request) use($app) {
    $friend_id = intval($request->get("friend_id"));
    $personModel = new PersonModel($app['db']);
    if (empty($personModel->findById($friend_id))) {
        throw new ValidationException("Unknown friend_id={$friend_id}");
    }
    $personModel->createFriendRequest($app["me"]["id"], $friend_id);
    return $app->json([], 204);
});
// Get the list of pending friendship requests
$app->get('/api/v1/person/pending/', function () use($app) {
    $personModel = new PersonModel($app['db']);
    $data = $personModel->getFriendRequests($app["me"]["id"]);
    return $app->json($data, 200);
});
// Decline friendship request
$app->post('/api/v1/person/decline/', function (Request $request) use($app) {
    $friend_id = intval($request->get("friend_id"));
    $personModel = new PersonModel($app['db']);
    if (empty($personModel->findById($friend_id))) {
        throw new ValidationException("Unknown friend_id={$friend_id}");
    }