Add frontend support for settings
This commit is contained in:
@@ -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<Settings[]> {
|
||||
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<Settings> {
|
||||
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<Settings>
|
||||
): Promise<Settings> {
|
||||
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<Script> {
|
||||
const response = await fetch(`${API_URL}/script/${id}`);
|
||||
|
||||
Reference in New Issue
Block a user