avant 50
This commit is contained in:
@@ -1,5 +1,37 @@
|
||||
import axios from 'axios'
|
||||
import axios, { type AxiosError } from 'axios'
|
||||
import { useToast } from '@/composables/useToast'
|
||||
|
||||
export default axios.create({
|
||||
const client = axios.create({
|
||||
baseURL: import.meta.env.VITE_API_URL ?? '',
|
||||
})
|
||||
|
||||
client.interceptors.response.use(
|
||||
response => response,
|
||||
(error: AxiosError<{ detail?: string; message?: string }>) => {
|
||||
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 as Array<{ msg?: string }>).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
|
||||
|
||||
@@ -56,6 +56,10 @@ export const gardensApi = {
|
||||
},
|
||||
delete: (id: number) => client.delete(`/api/gardens/${id}`),
|
||||
cells: (id: number) => client.get<GardenCell[]>(`/api/gardens/${id}/cells`).then(r => r.data),
|
||||
createCell: (id: number, cell: Partial<GardenCell>) =>
|
||||
client.post<GardenCell>(`/api/gardens/${id}/cells`, cell).then(r => r.data),
|
||||
updateCell: (id: number, cellId: number, cell: Partial<GardenCell>) =>
|
||||
client.put<GardenCell>(`/api/gardens/${id}/cells/${cellId}`, cell).then(r => r.data),
|
||||
measurements: (id: number) => client.get<Measurement[]>(`/api/gardens/${id}/measurements`).then(r => r.data),
|
||||
addMeasurement: (id: number, m: Partial<Measurement>) =>
|
||||
client.post<Measurement>(`/api/gardens/${id}/measurements`, m).then(r => r.data),
|
||||
|
||||
25
frontend/src/api/identify.ts
Normal file
25
frontend/src/api/identify.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import client from './client'
|
||||
|
||||
export interface DiagnosticResult {
|
||||
species: string
|
||||
common_name: string
|
||||
confidence: number
|
||||
conseil: string
|
||||
actions: string[]
|
||||
image_url?: string
|
||||
}
|
||||
|
||||
export interface IdentifyResponse {
|
||||
source: 'plantnet' | 'yolo' | 'cache'
|
||||
results: DiagnosticResult[]
|
||||
}
|
||||
|
||||
export const identifyApi = {
|
||||
identify: (file: File) => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
return client.post<IdentifyResponse>('/api/identify', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
}).then(r => r.data)
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ export interface Planting {
|
||||
garden_id: number
|
||||
variety_id: number
|
||||
cell_id?: number
|
||||
cell_ids?: number[] // multi-sélect zones
|
||||
date_plantation?: string
|
||||
quantite: number
|
||||
statut: string
|
||||
|
||||
Reference in New Issue
Block a user