ysdsd
All checks were successful
Deploy / deploy-staging (push) Successful in 6s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-29 02:21:22 +02:00
parent a0f19ff6b4
commit 4ead35047a
7 changed files with 180 additions and 4 deletions

View File

@@ -26,6 +26,11 @@ final class Router
$this->respond(['data' => $this->service->latestStatuses()]);
}
if ($path === 'v1/recent-fetches' && $method === 'GET') {
$limit = max(1, min(50, (int) ($_GET['limit'] ?? 12)));
$this->respond(['data' => $this->service->recentFetches($limit)]);
}
if ($path === 'v1/latest' && $method === 'GET') {
$symbols = $this->parseCsv($_GET['symbols'] ?? null);
$base = $this->stringOrNull($_GET['base'] ?? null);

View File

@@ -27,6 +27,11 @@ final class FxRatesService
return $this->repository->listLatestFetches();
}
public function recentFetches(int $limit = 20): array
{
return $this->repository->listRecentFetches($limit);
}
public function snapshot(?string $baseCurrency = null, ?string $at = null, ?array $symbols = null, ?int $windowMinutes = null): ?array
{
$base = $this->normalizeCurrency($baseCurrency ?: $this->defaultBaseCurrency());

View File

@@ -117,6 +117,23 @@ final class FxRatesRepository
return array_values($latestByBase);
}
public function listRecentFetches(int $limit = 20): array
{
$stmt = $this->pdo->prepare(
'SELECT id, provider, base_currency, rate_date, fetched_at, created_at
FROM ' . $this->table('fetches') . '
ORDER BY fetched_at DESC, id DESC
LIMIT :limit'
);
$stmt->bindValue(':limit', max(1, $limit), PDO::PARAM_INT);
$stmt->execute();
return array_map(
fn (array $row): array => $this->normalizeFetch($row),
$stmt->fetchAll(PDO::FETCH_ASSOC) ?: []
);
}
public function getSnapshotByFetchId(int $fetchId, ?array $symbols = null): ?array
{
$fetch = $this->getFetchById($fetchId);