Files
moonwell-web/app/Http/Controllers/Api/LauncherRealmController.php

74 lines
3.4 KiB
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Services\LauncherRealmService;
use Illuminate\Http\JsonResponse;
use OpenApi\Attributes as OA;
use Throwable;
class LauncherRealmController extends Controller
{
#[OA\Get(
path: '/api/launcher/realms',
summary: 'Получить список реалмов и их статус',
description: 'Возвращает реалмы из таблицы realmlist. Статус online означает, что игровой порт реалма доступен по TCP.',
tags: ['Launcher'],
responses: [
new OA\Response(
response: 200,
description: 'Список реалмов',
content: new OA\JsonContent(
properties: [
new OA\Property(
property: 'data',
type: 'array',
items: new OA\Items(
properties: [
new OA\Property(property: 'id', type: 'integer', example: 1),
new OA\Property(property: 'name', type: 'string', example: 'MoonWell'),
new OA\Property(property: 'address', type: 'string', example: 'logon.moon-well.online'),
new OA\Property(property: 'port', type: 'integer', example: 8085),
new OA\Property(property: 'icon', type: 'integer', example: 1),
new OA\Property(property: 'flag', type: 'integer', example: 0),
new OA\Property(property: 'timezone', type: 'integer', example: 4),
new OA\Property(property: 'population', type: 'number', format: 'float', example: 0.5),
new OA\Property(property: 'online', type: 'boolean', example: true),
new OA\Property(property: 'status', type: 'string', enum: ['online', 'offline'], example: 'online'),
],
),
),
new OA\Property(property: 'checked_at', type: 'string', format: 'date-time'),
],
),
),
new OA\Response(
response: 503,
description: 'Не удалось получить список реалмов',
content: new OA\JsonContent(
properties: [
new OA\Property(property: 'message', type: 'string', example: 'Не удалось получить список реалмов.'),
],
),
),
new OA\Response(response: 429, description: 'Слишком много запросов'),
],
)]
public function index(LauncherRealmService $realms): JsonResponse
{
try {
return response()->json([
'data' => $realms->realms(),
'checked_at' => now()->toIso8601String(),
]);
} catch (Throwable $exception) {
report($exception);
return response()->json([
'message' => 'Не удалось получить список реалмов.',
], 503);
}
}
}