blob: 26c5779fbd4141e65ffe0dbfc4e5b493f3b59f31 (
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
|
<?php
namespace JsonApi\Routes\Users;
use JsonApi\Errors\AuthorizationFailedException;
use JsonApi\Errors\RecordNotFoundException;
use JsonApi\JsonApiController;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class ContactsIndex extends JsonApiController
{
protected $allowedPagingParameters = ['offset', 'limit'];
public function __invoke(Request $request, Response $response, $args)
{
if (!$user = \User::find($args['id'])) {
throw new RecordNotFoundException();
}
if (!Authority::canEditUser($this->getUser($request), $user)) {
throw new AuthorizationFailedException();
}
$contacts = $user->contacts;
list($offset, $limit) = $this->getOffsetAndLimit();
return $this->getPaginatedContentResponse($contacts->limit($offset, $limit), count($contacts));
}
}
|