mirror of
git://f0xx.org/ac/ac-ms-tickets
synced 2026-07-29 04:18:33 +03:00
initial
This commit is contained in:
49
public/api/tickets.php
Normal file
49
public/api/tickets.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/../../src/bootstrap.php';
|
||||
|
||||
if (!Auth::user()) {
|
||||
json_out(['ok' => false, 'error' => 'unauthorized'], 401);
|
||||
}
|
||||
|
||||
$page = max(1, (int) ($_GET['page'] ?? 1));
|
||||
$perPage = (int) ($_GET['per_page'] ?? 50);
|
||||
if (!in_array($perPage, [25, 50, 75, 100, 200], true)) {
|
||||
$perPage = 50;
|
||||
}
|
||||
$sort = (string) ($_GET['sort'] ?? 'opened_at_ms');
|
||||
$dir = (string) ($_GET['dir'] ?? 'desc');
|
||||
$tag = trim((string) ($_GET['tag'] ?? ''));
|
||||
|
||||
try {
|
||||
Database::requireTicketsTable();
|
||||
$data = TicketRepository::listPage($page, $perPage, $sort, $dir, $tag);
|
||||
json_out(['ok' => true] + $data);
|
||||
} catch (RuntimeException $e) {
|
||||
error_log('tickets api: ' . $e->getMessage());
|
||||
$out = [
|
||||
'ok' => false,
|
||||
'error' => 'tickets_table_missing',
|
||||
'hint' => $e->getMessage(),
|
||||
];
|
||||
if (cfg('debug')) {
|
||||
try {
|
||||
$pdo = Database::pdo();
|
||||
$out['db_driver'] = Database::driver();
|
||||
$out['tickets_table'] = Database::ticketsTableExists($pdo);
|
||||
if (Database::isMysql()) {
|
||||
$out['mysql_database'] = $pdo->query('SELECT DATABASE()')->fetchColumn();
|
||||
}
|
||||
} catch (Throwable $diag) {
|
||||
$out['diag_error'] = $diag->getMessage();
|
||||
}
|
||||
}
|
||||
json_out($out, 503);
|
||||
} catch (Throwable $e) {
|
||||
error_log('tickets api: ' . $e->getMessage());
|
||||
$out = ['ok' => false, 'error' => 'list failed'];
|
||||
if (cfg('debug')) {
|
||||
$out['hint'] = $e->getMessage();
|
||||
}
|
||||
json_out($out, 500);
|
||||
}
|
||||
Reference in New Issue
Block a user