feat: full backend (untested)

This commit is contained in:
Nik L
2026-01-14 11:37:44 -05:00
parent 4a0db63a30
commit d585cf8613
32 changed files with 1317 additions and 57 deletions

View File

@@ -0,0 +1,78 @@
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000';
export interface ParticipantAPI {
id: string;
name: string;
email: string;
ics_url: string;
created_at: string;
updated_at: string;
}
export interface TimeSlotAPI {
day: string;
hour: number;
availability: 'full' | 'partial' | 'none';
availableParticipants: string[];
}
export interface CreateParticipantRequest {
name: string;
email: string;
ics_url: string;
}
async function handleResponse<T>(response: Response): Promise<T> {
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: 'Request failed' }));
throw new Error(error.detail || 'Request failed');
}
return response.json();
}
export async function fetchParticipants(): Promise<ParticipantAPI[]> {
const response = await fetch(`${API_URL}/api/participants`);
return handleResponse<ParticipantAPI[]>(response);
}
export async function createParticipant(data: CreateParticipantRequest): Promise<ParticipantAPI> {
const response = await fetch(`${API_URL}/api/participants`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
});
return handleResponse<ParticipantAPI>(response);
}
export async function deleteParticipant(id: string): Promise<void> {
const response = await fetch(`${API_URL}/api/participants/${id}`, {
method: 'DELETE',
});
if (!response.ok) {
throw new Error('Failed to delete participant');
}
}
export async function fetchAvailability(participantIds: string[]): Promise<TimeSlotAPI[]> {
const response = await fetch(`${API_URL}/api/availability`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ participant_ids: participantIds }),
});
const data = await handleResponse<{ slots: TimeSlotAPI[] }>(response);
return data.slots;
}
export async function syncCalendars(): Promise<void> {
const response = await fetch(`${API_URL}/api/sync`, { method: 'POST' });
if (!response.ok) {
throw new Error('Failed to sync calendars');
}
}
export async function syncParticipant(id: string): Promise<void> {
const response = await fetch(`${API_URL}/api/sync/${id}`, { method: 'POST' });
if (!response.ok) {
throw new Error('Failed to sync participant calendar');
}
}