forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShowResult.php
More file actions
34 lines (30 loc) · 931 Bytes
/
ShowResult.php
File metadata and controls
34 lines (30 loc) · 931 Bytes
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
<?php
namespace App\Http\Controllers\Api\V1;
use App\Http\Resources\V1\ResultResource;
use App\Models\Result;
use Http\Discovery\Exception\NotFoundException;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use OpenApi\Attributes as OA;
class ShowResult extends ApiController
{
#[OA\Get(
path: '/api/v1/results/{id}',
description: 'Get result.',
responses: [
new OA\Response(response: 200, description: 'OK'),
new OA\Response(response: Response::HTTP_NOT_FOUND, description: 'Result not found'),
])]
public function __invoke(Request $request, int $id)
{
$result = Result::findOr($id, function () {
self::throw(
e: new NotFoundException('Result not found.'),
code: 404,
);
});
return self::sendResponse(
data: new ResultResource($result),
);
}
}