diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 236b0d8..f37beb5 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -1,5 +1,15 @@ export const API_URL = 'http://127.0.0.1:8000'; +/** + * Type definitions for Settings + */ +export interface Settings { + id: number; + requirements: string; + environment: string; + user: string; +} + export async function checkHealth(): Promise<'healthy' | 'unhealthy'> { try { const response = await fetch(`${API_URL}/health`); @@ -58,6 +68,42 @@ export async function addScript( return response.json(); } +// Fetch all settings +export async function fetchSettings(): Promise { + const response = await fetch(`${API_URL}/settings`); + if (!response.ok) { + throw new Error('Failed to fetch settings ' + response.statusText); + } + return response.json(); +} + +// Fetch a single setting by ID +export async function fetchSettingById(id: number): Promise { + const response = await fetch(`${API_URL}/settings/${id}`); + if (!response.ok) { + throw new Error('Failed to fetch setting'); + } + return response.json(); +} + +// Update an existing setting +export async function updateSetting( + id: number, + updatedSetting: Partial +): Promise { + const response = await fetch(`${API_URL}/settings/${id}`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(updatedSetting) + }); + if (!response.ok) { + throw new Error('Failed to update setting'); + } + return response.json(); +} + // Fetch a single script by ID export async function fetchScriptById(id: number): Promise + +
+

Settings

+ + {#if $isLoading} +

Loading...

+ {:else if $error} +

{$error}

+ {:else} +
+ {#each $settings as setting (setting.id)} +
+ +
+ +
+ + +
+ +
+ + + + + +
+ {/each} +
+ {/if} +
+ +