From 32c7781d140433734e48ec0c8c00c696d8259fb2 Mon Sep 17 00:00:00 2001 From: gilles Date: Sun, 8 Mar 2026 19:28:19 +0100 Subject: [PATCH] =?UTF-8?q?feat(plantes):=20API=20plants.ts=20=E2=80=94=20?= =?UTF-8?q?Plant=20+=20PlantVariety=20+=20endpoints=20varieties?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remplace Plant (variete/boutique/tags inline) par Plant + PlantVariety séparés. Ajoute temp_germination, temps_levee_j, varieties[]. Ajoute CRUD variétés dans plantsApi. Corrige PlantesView et TachesView pour lire boutique/variete via varieties?.[0]. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/api/plants.ts | 66 ++++++++++++++++++++---------- frontend/src/views/PlantesView.vue | 41 ++++++++++--------- frontend/src/views/TachesView.vue | 2 +- 3 files changed, 66 insertions(+), 43 deletions(-) diff --git a/frontend/src/api/plants.ts b/frontend/src/api/plants.ts index 120da90..55038fb 100644 --- a/frontend/src/api/plants.ts +++ b/frontend/src/api/plants.ts @@ -1,29 +1,12 @@ +// frontend/src/api/plants.ts import client from './client' -export interface Plant { +export interface PlantVariety { id?: number - nom_commun: string - nom_botanique?: string + plant_id?: number variete?: string - famille?: string - categorie?: string // potager|fleur|arbre|arbuste tags?: string - type_plante?: string - besoin_eau?: string - besoin_soleil?: string - espacement_cm?: number - temp_min_c?: number - hauteur_cm?: number - plantation_mois?: string - recolte_mois?: string - semis_interieur_mois?: string - semis_exterieur_mois?: string - maladies_courantes?: string - astuces_culture?: string - url_reference?: string - notes?: string - associations_favorables?: string[] - associations_defavorables?: string[] + notes_variete?: string boutique_nom?: string boutique_url?: string prix_achat?: number @@ -32,10 +15,49 @@ export interface Plant { dluo?: string } +export interface Plant { + id?: number + nom_commun: string + nom_botanique?: string + famille?: string + categorie?: string // potager|fleur|arbre|arbuste + type_plante?: string + besoin_eau?: string + besoin_soleil?: string + espacement_cm?: number + temp_min_c?: number + hauteur_cm?: number + temp_germination?: string // ex: "8-10°C" + temps_levee_j?: string // ex: "15-20 jours" + plantation_mois?: string + recolte_mois?: string + semis_interieur_mois?: string + semis_exterieur_mois?: string + repiquage_mois?: string + profondeur_semis_cm?: number + duree_culture_j?: number + sol_conseille?: string + maladies_courantes?: string + astuces_culture?: string + url_reference?: string + notes?: string + associations_favorables?: string[] + associations_defavorables?: string[] + varieties?: PlantVariety[] +} + export const plantsApi = { - list: (categorie?: string) => client.get('/api/plants', { params: categorie ? { categorie } : {} }).then(r => r.data), + list: (categorie?: string) => + client.get('/api/plants', { params: categorie ? { categorie } : {} }).then(r => r.data), get: (id: number) => client.get(`/api/plants/${id}`).then(r => r.data), create: (p: Partial) => client.post('/api/plants', p).then(r => r.data), update: (id: number, p: Partial) => client.put(`/api/plants/${id}`, p).then(r => r.data), delete: (id: number) => client.delete(`/api/plants/${id}`), + // Variétés + createVariety: (plantId: number, v: Partial) => + client.post(`/api/plants/${plantId}/varieties`, v).then(r => r.data), + updateVariety: (plantId: number, vid: number, v: Partial) => + client.put(`/api/plants/${plantId}/varieties/${vid}`, v).then(r => r.data), + deleteVariety: (plantId: number, vid: number) => + client.delete(`/api/plants/${plantId}/varieties/${vid}`), } diff --git a/frontend/src/views/PlantesView.vue b/frontend/src/views/PlantesView.vue index 31a2861..7b83d55 100644 --- a/frontend/src/views/PlantesView.vue +++ b/frontend/src/views/PlantesView.vue @@ -102,7 +102,7 @@ › -

{{ detailPlant.variete }}

+

{{ detailPlant.varieties?.[0]?.variete }}

@@ -137,34 +137,34 @@ -
+

🛒 Approvisionnement

-
+
Enseigne - {{ detailPlant.boutique_nom }} + {{ detailPlant.varieties?.[0]?.boutique_nom }}
-
+
Prix - {{ detailPlant.prix_achat.toFixed(2) }} € + {{ detailPlant.varieties?.[0]?.prix_achat?.toFixed(2) }} €
-
+
Date d'achat - {{ detailPlant.date_achat }} + {{ detailPlant.varieties?.[0]?.date_achat }}
-
+
Poids / Qté - {{ detailPlant.poids }} + {{ detailPlant.varieties?.[0]?.poids }}
-
+
DLUO - - {{ detailPlant.dluo }}{{ isDluoExpired(detailPlant.dluo) ? ' ⚠️' : '' }} + + {{ detailPlant.varieties?.[0]?.dluo }}{{ isDluoExpired(detailPlant.varieties?.[0]?.dluo ?? '') ? ' ⚠️' : '' }}
- @@ -572,7 +572,7 @@ const filteredPlants = computed(() => { result = result.filter(p => { const group = plantGroups.value.get((p.nom_commun || '').toLowerCase()) || [] return group.some(v => - v.nom_commun?.toLowerCase().includes(q) || v.variete?.toLowerCase().includes(q) + v.nom_commun?.toLowerCase().includes(q) || v.varieties?.[0]?.variete?.toLowerCase().includes(q) ) }) } @@ -684,15 +684,16 @@ function startEdit(p: Plant) { closeDetail() editPlant.value = p + const v0 = p.varieties?.[0] Object.assign(form, { - nom_commun: p.nom_commun || '', variete: p.variete || '', famille: p.famille || '', + nom_commun: p.nom_commun || '', variete: v0?.variete || '', famille: p.famille || '', categorie: p.categorie || 'potager', besoin_eau: p.besoin_eau || 'moyen', besoin_soleil: p.besoin_soleil || 'plein soleil', plantation_mois: p.plantation_mois || '', notes: p.notes || '', associations_favorables: [...(withAssoc.associations_favorables ?? [])], associations_defavorables: [...(withAssoc.associations_defavorables ?? [])], - boutique_nom: p.boutique_nom || '', boutique_url: p.boutique_url || '', - prix_achat: p.prix_achat ?? null, date_achat: p.date_achat || '', - poids: p.poids || '', dluo: p.dluo || '', + boutique_nom: v0?.boutique_nom || '', boutique_url: v0?.boutique_url || '', + prix_achat: v0?.prix_achat ?? null, date_achat: v0?.date_achat || '', + poids: v0?.poids || '', dluo: v0?.dluo || '', }) assocFilter.value = '' showAssocModal.value = false diff --git a/frontend/src/views/TachesView.vue b/frontend/src/views/TachesView.vue index 14d60d5..447526b 100644 --- a/frontend/src/views/TachesView.vue +++ b/frontend/src/views/TachesView.vue @@ -416,7 +416,7 @@ const plantingsByGarden = computed(() => { function plantingLabel(p: Planting): string { const plant = plantsStore.plants.find(pl => pl.id === p.variety_id) const nom = plant - ? [plant.nom_commun, plant.variete].filter(Boolean).join(' — ') + ? [plant.nom_commun, plant.varieties?.[0]?.variete].filter(Boolean).join(' — ') : `Variété #${p.variety_id}` const date = p.date_plantation ? ` (${fmtDate(p.date_plantation)})` : '' return `${nom}${date}`