aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/actor.php
blob: 5879538d168cffb0c74671fa20e9b6c4565362a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php

use WpfTest\HttpResponseStatus\NotFound;
use WpfTest\Model\Actor;
use WpfTest\Model\Note;
use WpfTest\Router;

Router::getInstance()->mount('/user/:handle', function (array $args) {
    $actor = Actor::findLocalByHandle($args['handle']);
    if ($actor == null) {
        throw new NotFound("i don't know any local user called " . $args['handle']);
    }
    json_response($actor);
});

Router::getInstance()->mount('/user/:handle/basicFeed', function (array $args) {
    $actor = Actor::findLocalByHandle($args['handle']);
    $notes = Note::findAllWithAuthor($actor);
    // TODO: implement pagination
    json_response([
        'page' => 1,
        'totalPages' => 1,
        'nextPage' => null,
        'previousPage' => null,
        'items' => array_map(function (Note $note) {
            return $note->uri;
        }, $notes)
    ]);
});

Router::getInstance()->mount('/user/:handle/fullFeed', function (array $args) {
    $actor = Actor::findLocalByHandle($args['handle']);
    $notes = Note::findAllWithAuthor($actor);
    // TODO: implement pagination here as well
    json_response([
        'page' => 1,
        'totalPages' => 1,
        'nextPage' => null,
        'previousPage' => null,
        'items' => $notes
    ]);
});