api: add Person and StreamingService contexts

This commit is contained in:
Cron1cle
2025-10-07 20:08:51 +02:00
parent de2778d6db
commit 2dacb9fa80
12 changed files with 390 additions and 111 deletions

40
apis/personApi.ts Normal file
View File

@@ -0,0 +1,40 @@
export type PersonHistorySeasonRaw = {
seasonId: number;
show: number;
seasonNumber: number;
startDate?: string;
endDate?: string | null;
seasonParticipants: any[];
};
export type PersonHistoryEntry = {
showId: number;
seasonId: number;
seasonNumber: number;
};
const PERSON_API_BASE = "http://45.157.177.99:8080/persons";
export async function getPersonHistory(
personId: number
): Promise<PersonHistoryEntry[]> {
const url = `${PERSON_API_BASE}/${personId}/history`;
try {
console.log("[getPersonHistory] Fetch:", url);
const res = await fetch(url);
if (!res.ok) throw new Error("History fetch failed " + res.status);
const data: unknown = await res.json();
if (!Array.isArray(data)) {
console.warn("History expected array, got:", data);
return [];
}
return (data as PersonHistorySeasonRaw[]).map((s) => ({
showId: s.show,
seasonId: s.seasonId,
seasonNumber: s.seasonNumber,
}));
} catch (e) {
console.error("getPersonHistory error:", e);
return [];
}
}