blob: 7953f4517f374f06449bd767cb1dfe3b74ee20b8 (
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
|
<?php
namespace JsonApi\Routes\Consultations;
use JsonApi\Errors\AuthorizationFailedException;
use JsonApi\Errors\RecordNotFoundException;
use JsonApi\JsonApiController;
use JsonApi\Schemas\ConsultationSlot;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class SlotsByBlockIndex extends JsonApiController
{
protected $allowedIncludePaths = [
ConsultationSlot::REL_BLOCK,
ConsultationSlot::REL_BOOKINGS,
];
protected $allowedPagingParameters = ['offset', 'limit'];
public function __invoke(Request $request, Response $response, $args)
{
$block = \ConsultationBlock::find($args['id']);
if (!$block) {
throw new RecordNotFoundException();
}
if (!Authority::canShowBlock($this->getUser($request), $block)) {
throw new AuthorizationFailedException();
}
[$offset, $limit] = $this->getOffsetAndLimit();
return $this->getPaginatedContentResponse(
$block->slots->limit($offset, $limit),
count($block->slots)
);
}
}
|