forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListSpeedtestServers.php
More file actions
57 lines (52 loc) · 1.81 KB
/
ListSpeedtestServers.php
File metadata and controls
57 lines (52 loc) · 1.81 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
<?php
namespace App\Http\Controllers\Api\V1;
use App\Actions\GetOoklaSpeedtestServers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use OpenApi\Attributes as OA;
class ListSpeedtestServers extends ApiController
{
#[OA\Get(
path: '/api/v1/ookla/list-servers',
summary: 'List available Ookla speedtest servers',
operationId: 'listSpeedtestServers',
tags: ['Servers'],
responses: [
new OA\Response(
response: Response::HTTP_OK,
description: 'OK',
content: new OA\JsonContent(
ref: '#/components/schemas/ServersCollection'
)
),
new OA\Response(
response: Response::HTTP_UNAUTHORIZED,
description: 'Unauthenticated',
content: new OA\JsonContent(ref: '#/components/schemas/UnauthenticatedError')
),
new OA\Response(
response: Response::HTTP_FORBIDDEN,
description: 'Forbidden',
content: new OA\JsonContent(
ref: '#/components/schemas/ForbiddenError',
example: ['message' => 'You do not have permission to view speedtest servers.']
)
),
]
)]
public function __invoke(Request $request)
{
if ($request->user()->tokenCant('ookla:list-servers')) {
return self::sendResponse(
data: null,
message: 'You do not have permission to view speedtest servers.',
code: Response::HTTP_FORBIDDEN,
);
}
$servers = GetOoklaSpeedtestServers::run();
return self::sendResponse(
data: $servers,
message: 'Speedtest servers fetched successfully.'
);
}
}