From 69844bfebc95922158416fafb3c5af5b66925135 Mon Sep 17 00:00:00 2001 From: tristan Date: Wed, 29 Apr 2026 10:11:24 +0200 Subject: [PATCH] =?UTF-8?q?feat(front)=20:=20logique=20Ajouter=20un=20bovi?= =?UTF-8?q?n=20sur=20=C3=A9cran=20de=20saisie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 (1M context) --- frontend/pages/entry-exit/entry/[id].vue | 43 +++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/frontend/pages/entry-exit/entry/[id].vue b/frontend/pages/entry-exit/entry/[id].vue index 8bc99d0..58fc83c 100644 --- a/frontend/pages/entry-exit/entry/[id].vue +++ b/frontend/pages/entry-exit/entry/[id].vue @@ -181,8 +181,48 @@ const loadReception = async () => { resetForm() } +const loadSavedBovines = async () => { + const response = await api.get<{ 'hydra:member'?: BovineData[] } | BovineData[]>( + `bovines?reception=${receptionId.value}`, + {}, + { toast: false } + ) + savedBovines.value = Array.isArray(response) + ? response + : (response['hydra:member'] ?? []) +} + +const focusFirstField = () => { + const el = document.querySelector('form input[type="text"]') + el?.focus() +} + const addBovine = async () => { - // implémenté en Task 9 + if (!isFormValid.value || isAdding.value) return + + isAdding.value = true + try { + const payload = { + nationalNumber: form.nationalNumber.trim(), + receivedWeight: form.receivedWeight, + pricePerKg: form.pricePerKg, + arrivalDate: form.arrivalDate, + supplier: `/api/suppliers/${form.supplierId}`, + buildingCase: `/api/building_cases/${form.caseId}`, + reception: `/api/receptions/${receptionId.value}` + } + + await api.post('bovines', payload, { + headers: { 'Content-Type': 'application/ld+json' } + }) + + await loadSavedBovines() + resetForm() + await nextTick() + focusFirstField() + } finally { + isAdding.value = false + } } onMounted(async () => { @@ -191,5 +231,6 @@ onMounted(async () => { getBuildingList() ]) await loadReception() + await loadSavedBovines() })