ADD: added initial page with login

This commit is contained in:
hwinkel
2025-05-20 22:58:31 +02:00
parent 214ab55ad2
commit a330291456
25 changed files with 1064 additions and 35 deletions

View File

@@ -0,0 +1,45 @@
const API_URL = 'http://localhost:8080/api';
export async function login(email: string, password: string) {
const res = await fetch(`${API_URL}/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password }),
});
if (!res.ok) throw new Error('Login fehlgeschlagen');
return res.json(); // { token: string }
}
export async function fetchTournaments() {
const res = await fetch(`${API_URL}/tournaments`);
if (!res.ok) throw new Error('Fehler beim Laden der Turniere');
return res.json();
}
export async function fetchTournament(id: string, token?: string) {
const res = await fetch(`${API_URL}/tournaments/${id}`, {
headers: token ? { Authorization: `Bearer ${token}` } : undefined,
});
if (!res.ok) throw new Error('Fehler beim Laden des Turniers');
return res.json();
}
export async function updateTournament(id: string, data: any, token: string) {
const res = await fetch(`${API_URL}/tournaments/${id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
body: JSON.stringify(data),
});
if (!res.ok) throw new Error('Update fehlgeschlagen');
return res.json();
}
export async function registerTeam(id: string, team: { name: string }, token: string) {
const res = await fetch(`${API_URL}/tournaments/${id}/register`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
body: JSON.stringify(team),
});
if (!res.ok) throw new Error('Team-Anmeldung fehlgeschlagen');
return res.json();
}