This commit is contained in:
2026-03-08 10:04:14 +01:00
parent 7967f63fea
commit 14636bd58f
74 changed files with 14180 additions and 4453 deletions
+29 -1
View File
@@ -1,4 +1,32 @@
import axios from 'axios';
export default axios.create({
import { useToast } from '@/composables/useToast';
const client = axios.create({
baseURL: import.meta.env.VITE_API_URL ?? '',
});
client.interceptors.response.use(response => response, (error) => {
const { error: showError } = useToast();
if (error.response) {
const status = error.response.status;
const detail = error.response.data?.detail ?? error.response.data?.message;
if (status === 422) {
const msg = Array.isArray(detail)
? detail.map(d => d.msg ?? d).join(', ')
: (detail ?? 'Vérifiez les champs du formulaire');
showError(`Données invalides : ${msg}`);
}
else if (status === 404) {
showError('Ressource introuvable');
}
else if (status >= 500) {
showError(`Erreur serveur (${status}) — réessayez dans un instant`);
}
else if (status !== 401 && status !== 403) {
showError(String(detail ?? `Erreur ${status}`));
}
}
else if (error.request) {
showError('Serveur inaccessible — vérifiez votre connexion réseau');
}
return Promise.reject(error);
});
export default client;
+2
View File
@@ -11,6 +11,8 @@ export const gardensApi = {
},
delete: (id) => client.delete(`/api/gardens/${id}`),
cells: (id) => client.get(`/api/gardens/${id}/cells`).then(r => r.data),
createCell: (id, cell) => client.post(`/api/gardens/${id}/cells`, cell).then(r => r.data),
updateCell: (id, cellId, cell) => client.put(`/api/gardens/${id}/cells/${cellId}`, cell).then(r => r.data),
measurements: (id) => client.get(`/api/gardens/${id}/measurements`).then(r => r.data),
addMeasurement: (id, m) => client.post(`/api/gardens/${id}/measurements`, m).then(r => r.data),
};
+10
View File
@@ -0,0 +1,10 @@
import client from './client';
export const identifyApi = {
identify: (file) => {
const formData = new FormData();
formData.append('file', file);
return client.post('/api/identify', formData, {
headers: { 'Content-Type': 'multipart/form-data' }
}).then(r => r.data);
}
};
+8
View File
@@ -22,6 +22,14 @@ export interface Plant {
astuces_culture?: string
url_reference?: string
notes?: string
associations_favorables?: string[]
associations_defavorables?: string[]
boutique_nom?: string
boutique_url?: string
prix_achat?: number
date_achat?: string
poids?: string
dluo?: string
}
export const plantsApi = {