basic profile
This commit is contained in:
48
packages/frontend/src/services/api.js
Normal file
48
packages/frontend/src/services/api.js
Normal file
@@ -0,0 +1,48 @@
|
||||
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
|
||||
};
|
||||
Reference in New Issue
Block a user