public function testGetFriendRequests()
 {
     $this->setupModel(array(["row" => [["id" => 1, "name" => "Person1"]]], ["row" => [["id" => 2, "name" => "Person2"]]], ["row" => [["id" => 3, "name" => "Person3"]]]));
     $res = $this->model->getFriendRequests(1);
     $this->assertArrayHasKey("id", $res[0]);
     $this->assertArrayHasKey("name", $res[0]);
     $this->assertTrue(3 === count($res));
 }
示例#2
0
    $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}");
    }
    $personModel->deleteFriendRequest($friend_id, $app["me"]["id"]);
    return $app->json([], 204);
});
// Accept friendship request
$app->post('/api/v1/person/accept/', 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->addFriend($app["me"]["id"], $friend_id);
    return $app->json([], 204);
});
// Get the list of your friends on level N
$app->get('/api/v1/friends', function (Request $request) use($app) {
    $level = intval($request->get("level", 1));
    $personModel = new PersonModel($app['db']);
    $data = $personModel->getFriends($app["me"]["id"], $level);
    return $app->json($data, 200);
});
$app->run();