Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| LogisticsEventEndpoint | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
3.02 | |
0.00% |
0 / 1 |
| handle | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
3.02 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace LambdaTwelve\OneRecord\Server\Endpoint; |
| 6 | |
| 7 | use LambdaTwelve\OneRecord\JsonLd\Context; |
| 8 | use LambdaTwelve\OneRecord\Server\Http\HttpException; |
| 9 | use LambdaTwelve\OneRecord\Server\Http\Negotiated; |
| 10 | use LambdaTwelve\OneRecord\Server\Http\Responder; |
| 11 | use LambdaTwelve\OneRecord\Server\Spi\Action; |
| 12 | use LambdaTwelve\OneRecord\Server\Spi\Agent; |
| 13 | use LambdaTwelve\OneRecord\Vocabulary\Generated\Cargo; |
| 14 | use Psr\Http\Message\ResponseInterface; |
| 15 | use Psr\Http\Message\ServerRequestInterface; |
| 16 | |
| 17 | /** |
| 18 | * GET /logistics-objects/{id}/logistics-events/{eventId}: one event. Access |
| 19 | * follows GET_LOGISTICS_EVENT on the object. |
| 20 | */ |
| 21 | final class LogisticsEventEndpoint extends AbstractEndpoint |
| 22 | { |
| 23 | public function handle(ServerRequestInterface $request, Agent $agent, Negotiated $negotiated, array $parameters): ResponseInterface |
| 24 | { |
| 25 | $stored = $this->requireObject($parameters['id'], $agent, Action::ReadLogisticsEvent); |
| 26 | $eventIri = $this->services->config->logisticsEventIri($parameters['id'], $parameters['eventId']); |
| 27 | $event = $this->services->events->get($eventIri); |
| 28 | if ($event === null || !$event->logisticsObject->equals($stored->object->iri)) { |
| 29 | throw HttpException::notFound('Logistics Event', $eventIri->value); |
| 30 | } |
| 31 | $context = Context::oneRecord(); |
| 32 | $type = $this->services->vocabulary->mostSpecific($event->types())[0] ?? Cargo::LogisticsEvent; |
| 33 | |
| 34 | return $this->services->responder->jsonLd(200, $event->toJsonLd($context), $negotiated, $type, ['Location' => $eventIri->value, 'Last-Modified' => Responder::httpDate($event->created)], self::isHead($request)); |
| 35 | } |
| 36 | } |