aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/lib')
-rw-r--r--frontend/src/lib/api.ts43
-rw-r--r--frontend/src/lib/types.ts8
2 files changed, 48 insertions, 3 deletions
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts
index 0be9148..239c598 100644
--- a/frontend/src/lib/api.ts
+++ b/frontend/src/lib/api.ts
@@ -1,4 +1,4 @@
-import type { Service, Heartbeat, ServiceStats } from './types';
+import type { Service, Heartbeat, ServiceStats, PaginatedResponse } from './types';
const BASE = '/api';
@@ -26,8 +26,8 @@ export async function deleteService(id: number): Promise<void> {
if (!res.ok) throw new Error('falha ao remover serviço');
}
-export async function getHistory(id: number): Promise<Heartbeat[]> {
- const res = await fetch(`${BASE}/services/${id}/history`);
+export async function getHistory(id: number, page = 1, perPage = 50): Promise<PaginatedResponse<Heartbeat>> {
+ const res = await fetch(`${BASE}/services/${id}/history?page=${page}&per_page=${perPage}`);
if (!res.ok) throw new Error('falha ao obter histórico');
return res.json();
}
@@ -37,3 +37,40 @@ export async function getServiceStats(id: number): Promise<ServiceStats> {
if (!res.ok) throw new Error('falha ao obter estatísticas');
return res.json();
}
+
+export async function listMaintenances(): Promise<Maintenance[]> {
+ const res = await fetch(`${BASE}/maintenances`);
+ if (!res.ok) throw new Error('falha ao listar manutenções');
+ return res.json();
+}
+
+export async function createMaintenance(data: { title: string; start_time: string; end_time: string }): Promise<Maintenance> {
+ const res = await fetch(`${BASE}/maintenances`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(data)
+ });
+ if (!res.ok) {
+ const err = await res.json().catch(() => ({}));
+ throw new Error(err.error || 'falha ao criar manutenção');
+ }
+ return res.json();
+}
+
+export async function updateMaintenance(id: number, data: { title: string; start_time: string; end_time: string; is_active: boolean }): Promise<Maintenance> {
+ const res = await fetch(`${BASE}/maintenances/${id}`, {
+ method: 'PUT',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(data)
+ });
+ if (!res.ok) {
+ const err = await res.json().catch(() => ({}));
+ throw new Error(err.error || 'falha ao atualizar manutenção');
+ }
+ return res.json();
+}
+
+export async function deleteMaintenance(id: number): Promise<void> {
+ const res = await fetch(`${BASE}/maintenances/${id}`, { method: 'DELETE' });
+ if (!res.ok) throw new Error('falha ao remover manutenção');
+}
diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts
index f80c933..594ab05 100644
--- a/frontend/src/lib/types.ts
+++ b/frontend/src/lib/types.ts
@@ -30,6 +30,14 @@ export interface Heartbeat {
tested_at: string;
}
+export interface PaginatedResponse<T> {
+ data: T[];
+ page: number;
+ per_page: number;
+ total: number;
+ total_pages: number;
+}
+
export interface ServiceStats {
service_id: number;
uptime_24h: number;