Main update
This commit is contained in:
@@ -23,6 +23,84 @@ if ($normalized === 'v1/chart-data') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($normalized === 'v1/cron/refresh-quotes' && strtoupper((string) ($_SERVER['REQUEST_METHOD'] ?? 'GET')) === 'POST') {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
try {
|
||||
$result = module_fn('boersenchecker', 'scheduled_refresh_quotes', [
|
||||
'trigger_source' => 'cron',
|
||||
]);
|
||||
http_response_code(!empty($result['ok']) ? 200 : 500);
|
||||
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
} catch (\Throwable $exception) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'message' => $exception->getMessage(),
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($normalized === 'v1/widget/refresh-quotes' && strtoupper((string) ($_SERVER['REQUEST_METHOD'] ?? 'GET')) === 'POST') {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
try {
|
||||
$result = module_fn('boersenchecker', 'scheduled_refresh_quotes', [
|
||||
'trigger_source' => 'widget',
|
||||
]);
|
||||
http_response_code(!empty($result['ok']) ? 200 : 500);
|
||||
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
} catch (\Throwable $exception) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'message' => $exception->getMessage(),
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($normalized === 'v1/widget/status' && strtoupper((string) ($_SERVER['REQUEST_METHOD'] ?? 'GET')) === 'GET') {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
try {
|
||||
$pdo = module_fn('boersenchecker', 'pdo');
|
||||
$quoteTable = module_fn('boersenchecker', 'table', 'quotes');
|
||||
$instrumentTable = module_fn('boersenchecker', 'table', 'instruments');
|
||||
$positionTable = module_fn('boersenchecker', 'table', 'positions');
|
||||
$settings = modules()->settings('boersenchecker');
|
||||
|
||||
$latestAt = $pdo->query('SELECT MAX(quoted_at) FROM ' . $quoteTable)->fetchColumn();
|
||||
$countStmt = $pdo->query(
|
||||
'SELECT COUNT(DISTINCT i.id)
|
||||
FROM ' . $positionTable . ' p
|
||||
INNER JOIN ' . $instrumentTable . ' i ON i.id = p.instrument_id
|
||||
WHERE i.symbol IS NOT NULL
|
||||
AND i.symbol <> \'\''
|
||||
);
|
||||
$trackedCount = (int) ($countStmt->fetchColumn() ?: 0);
|
||||
|
||||
$statusText = $latestAt
|
||||
? 'Letzter Kursabruf: ' . date('d.m.Y H:i', strtotime((string) $latestAt)) . ' · ' . $trackedCount . ' Titel'
|
||||
: 'Noch keine gespeicherten Kurse vorhanden.';
|
||||
|
||||
echo json_encode([
|
||||
'ok' => true,
|
||||
'data' => [
|
||||
'status_text' => $statusText,
|
||||
'latest_quoted_at' => $latestAt,
|
||||
'tracked_instruments' => $trackedCount,
|
||||
'report_currency' => (string) ($settings['report_currency'] ?? 'EUR'),
|
||||
],
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
} catch (\Throwable $exception) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
'ok' => false,
|
||||
'message' => $exception->getMessage(),
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode([
|
||||
|
||||
Reference in New Issue
Block a user