blob: 406d5d5af7825068bca31f40e9582438e93bd8c8 (
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
43
44
|
<?php
namespace JsonApi\Routes\Consultations;
use JsonApi\Errors\AuthorizationFailedException;
use JsonApi\Errors\RecordNotFoundException;
use JsonApi\JsonApiController;
use JsonApi\Routes\ValidationTrait;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class BookingsDelete extends JsonApiController
{
use ValidationTrait;
public function __invoke(Request $request, Response $response, $args)
{
$body = (string) $request->getBody();
if ($body) {
$json = $this->validate($request);
} else {
$json = [];
}
$booking = \ConsultationBooking::find($args['id']);
if (!$booking) {
throw new RecordNotFoundException();
}
$user = $this->getUser($request);
if (!Authority::canEditBooking($user, $booking)) {
throw new AuthorizationFailedException();
}
$reason = self::arrayGet($json, 'data.attributes.reason', '');
$booking->cancel($reason);
return $this->getCodeResponse(204);
}
protected function validateResourceDocument($json, $data)
{
}
}
|