api: add Person and StreamingService contexts
This commit is contained in:
40
apis/personApi.ts
Normal file
40
apis/personApi.ts
Normal 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 [];
|
||||
}
|
||||
}
|
||||
@@ -41,14 +41,13 @@ export async function getSeason(
|
||||
showId: number,
|
||||
seasonNumber: number
|
||||
): Promise<Season | null> {
|
||||
// WICHTIG: trailing Slash entfernt
|
||||
const url = `${SEASON_BASE_URL}/${showId}/seasons/${seasonNumber}`;
|
||||
try {
|
||||
console.log("[getSeason] Fetch:", url);
|
||||
const res = await fetch(url);
|
||||
console.log("[getSeason] Status:", res.status);
|
||||
if (res.status === 404) return null;
|
||||
if (!res.ok) throw new Error(`Season fetch failed: ${res.status}`);
|
||||
if (!res.ok) throw new Error("Season fetch failed " + res.status);
|
||||
const raw: RawSeason = await res.json();
|
||||
const participants: SeasonParticipant[] = raw.seasonParticipants.map(
|
||||
(p) => ({
|
||||
|
||||
29
apis/streamingServiceApi.ts
Normal file
29
apis/streamingServiceApi.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export type StreamingServiceRaw = {
|
||||
id: number;
|
||||
key: string;
|
||||
value: string;
|
||||
};
|
||||
|
||||
const STREAMING_SERVICE_API_URL = "http://45.157.177.99:8080/config";
|
||||
|
||||
export async function getStreamingImages(): Promise<StreamingServiceRaw[]> {
|
||||
try {
|
||||
const response = await fetch(STREAMING_SERVICE_API_URL);
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
const data: unknown = await response.json();
|
||||
if (!Array.isArray(data)) {
|
||||
console.warn("Expected array, got:", data);
|
||||
return [];
|
||||
}
|
||||
return (data as StreamingServiceRaw[]).map((s) => ({
|
||||
id: s.id,
|
||||
key: s.key,
|
||||
value: s.value,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error("Fetch error:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user