2026-06-19 17:23:25 +03:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use Nechaev\Reports\Features\Reports\ReportsApi;
|
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../init.php';
|
|
|
|
|
|
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
|
|
|
|
|
|
$method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
|
|
|
|
|
$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
|
|
|
|
|
|
|
|
|
|
if ($method === 'OPTIONS') {
|
|
|
|
|
http_response_code(204);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$api = new ReportsApi();
|
|
|
|
|
|
|
|
|
|
if ($method === 'GET' && $path === '/api/teams') {
|
|
|
|
|
echo json_encode($api->getTeams(), JSON_UNESCAPED_UNICODE);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-19 18:29:44 +03:00
|
|
|
if ($method === 'GET' && $path === '/api/config') {
|
|
|
|
|
echo json_encode($api->getPublicConfig(), JSON_UNESCAPED_UNICODE);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-19 17:23:25 +03:00
|
|
|
if ($method === 'GET' && preg_match('#^/api/teams/(\d+)/sprints$#', $path, $matches)) {
|
|
|
|
|
echo json_encode($api->getSprintsByTeamId((int) $matches[1]), JSON_UNESCAPED_UNICODE);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-19 18:29:44 +03:00
|
|
|
if ($method === 'GET' && preg_match('#^/api/sprints/(\d+)/tasks$#', $path, $matches)) {
|
|
|
|
|
echo json_encode($api->getTasksBySprintId((int) $matches[1]), JSON_UNESCAPED_UNICODE);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($method === 'GET' && preg_match('#^/api/sprints/(\d+)$#', $path, $matches)) {
|
|
|
|
|
$sprint = $api->getSprintById((int) $matches[1]);
|
|
|
|
|
if ($sprint === null) {
|
|
|
|
|
http_response_code(404);
|
|
|
|
|
echo json_encode(['error' => 'Sprint not found'], JSON_UNESCAPED_UNICODE);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
echo json_encode($sprint, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-19 17:23:25 +03:00
|
|
|
http_response_code(404);
|
|
|
|
|
echo json_encode(['error' => 'Not found'], JSON_UNESCAPED_UNICODE);
|
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
|
http_response_code(500);
|
|
|
|
|
echo json_encode(['error' => $e->getMessage()], JSON_UNESCAPED_UNICODE);
|
|
|
|
|
}
|