const API_BASE_URL = import.meta.env.VITE_API_URL || '/api'; const handleResponse = async (response) => { if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.detail || 'Si รจ verificato un errore'); } return response.json(); }; export const getCelebrities = async () => { const response = await fetch(`${API_BASE_URL}/celebrities/`); return handleResponse(response); }; export const getCelebrityById = async (id) => { const response = await fetch(`${API_BASE_URL}/celebrities/${id}`); return handleResponse(response); }; export const createCelebrity = async (celebrityData) => { const response = await fetch(`${API_BASE_URL}/celebrities/`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(celebrityData), }); return handleResponse(response); }; export const updateCelebrity = async (id, celebrityData) => { const response = await fetch(`${API_BASE_URL}/celebrities/${id}`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(celebrityData), }); return handleResponse(response); }; export const deleteCelebrity = async (id) => { const response = await fetch(`${API_BASE_URL}/celebrities/${id}`, { method: 'DELETE', }); if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.detail || 'Errore durante l\'eliminazione'); } return response.json(); // O un messaggio di successo };