From f4085228f91e78f8138a412b218e7a9efaa6a09e Mon Sep 17 00:00:00 2001 From: Alex Blank Date: Mon, 11 May 2026 21:44:53 +0200 Subject: [PATCH] feat: add backup monitoring API client --- frontend/src/api/backups.ts | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 frontend/src/api/backups.ts diff --git a/frontend/src/api/backups.ts b/frontend/src/api/backups.ts new file mode 100644 index 0000000..dcf24cb --- /dev/null +++ b/frontend/src/api/backups.ts @@ -0,0 +1,63 @@ +import { + BackupAlert, + BackupDashboardSummary, + BackupJob, + BackupRun, +} from "../types/backups"; + +const API_BASE = "/api"; + +export async function fetchBackupJobs(): Promise { + const res = await fetch(`${API_BASE}/backups/jobs`); + if (!res.ok) throw new Error("Failed to fetch backup jobs"); + return res.json(); +} + +export async function fetchBackupJob(jobId: string): Promise<{ job: BackupJob; runs: BackupRun[] }> { + const res = await fetch(`${API_BASE}/backups/jobs/${jobId}`); + if (!res.ok) throw new Error("Failed to fetch backup job"); + return res.json(); +} + +export async function fetchBackupRuns(jobId?: string, status?: string): Promise { + const params = new URLSearchParams(); + if (jobId) params.append("job_id", jobId); + if (status) params.append("status", status); + const res = await fetch(`${API_BASE}/backups/runs?${params}`); + if (!res.ok) throw new Error("Failed to fetch backup runs"); + return res.json(); +} + +export async function fetchBackupRun(runId: string): Promise { + const res = await fetch(`${API_BASE}/backups/runs/${runId}`); + if (!res.ok) throw new Error("Failed to fetch backup run"); + return res.json(); +} + +export async function fetchBackupAlerts( + jobId?: string, + acknowledged?: boolean, + severity?: string +): Promise { + const params = new URLSearchParams(); + if (jobId) params.append("job_id", jobId); + if (acknowledged !== undefined) params.append("acknowledged", String(acknowledged)); + if (severity) params.append("severity", severity); + const res = await fetch(`${API_BASE}/backups/alerts?${params}`); + if (!res.ok) throw new Error("Failed to fetch backup alerts"); + return res.json(); +} + +export async function acknowledgeBackupAlert(alertId: string): Promise { + const res = await fetch(`${API_BASE}/backups/alerts/${alertId}/acknowledge`, { + method: "POST", + }); + if (!res.ok) throw new Error("Failed to acknowledge alert"); + return res.json(); +} + +export async function fetchBackupDashboard(): Promise { + const res = await fetch(`${API_BASE}/dashboard/backups`); + if (!res.ok) throw new Error("Failed to fetch backup dashboard"); + return res.json(); +}