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
59 lines (55 loc) · 1.76 KB
/
ShowResult.php
File metadata and controls
59 lines (55 loc) · 1.76 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?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}',
summary: 'Fetch a single result by ID',
operationId: 'getResult',
tags: ['Results'],
parameters: [
new OA\Parameter(
name: 'id',
in: 'path',
required: true,
schema: new OA\Schema(type: 'integer'),
description: 'The ID of the result'
),
],
responses: [
new OA\Response(
response: Response::HTTP_OK,
description: 'OK',
content: new OA\JsonContent(ref: '#/components/schemas/ResultResponse')
),
new OA\Response(
response: Response::HTTP_UNAUTHORIZED,
description: 'Unauthenticated',
content: new OA\JsonContent(ref: '#/components/schemas/UnauthenticatedError')
),
new OA\Response(
response: Response::HTTP_NOT_FOUND,
description: 'Result not found',
content: new OA\JsonContent(ref: '#/components/schemas/NotFoundError')
),
]
)]
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),
);
}
}