diff --git a/frontend/src/api/achats.ts b/frontend/src/api/achats.ts new file mode 100644 index 0000000..d5c4c58 --- /dev/null +++ b/frontend/src/api/achats.ts @@ -0,0 +1,28 @@ +// frontend/src/api/achats.ts +import client from './client' + +export interface AchatIntrant { + id?: number + categorie: string // terreau | engrais | traitement | autre + nom: string + marque?: string + boutique_nom?: string + boutique_url?: string + prix?: number + poids?: string + date_achat?: string + dluo?: string + notes?: string + jardin_id?: number + plantation_id?: number + tache_id?: number +} + +export const achatsApi = { + list: (params?: { categorie?: string; jardin_id?: number }) => + client.get('/api/achats', { params }).then(r => r.data), + get: (id: number) => client.get(`/api/achats/${id}`).then(r => r.data), + create: (a: Partial) => client.post('/api/achats', a).then(r => r.data), + update: (id: number, a: Partial) => client.put(`/api/achats/${id}`, a).then(r => r.data), + delete: (id: number) => client.delete(`/api/achats/${id}`), +} diff --git a/frontend/src/api/fabrications.ts b/frontend/src/api/fabrications.ts new file mode 100644 index 0000000..c766d56 --- /dev/null +++ b/frontend/src/api/fabrications.ts @@ -0,0 +1,32 @@ +// frontend/src/api/fabrications.ts +import client from './client' + +export interface Ingredient { + nom: string + quantite: string +} + +export interface Fabrication { + id?: number + type: string // compost | decoction | purin | autre + nom: string + ingredients?: Ingredient[] + date_debut?: string + date_fin_prevue?: string + statut?: string // en_cours | pret | utilise | echec + quantite_produite?: string + notes?: string + jardin_id?: number + plantation_id?: number + tache_id?: number +} + +export const fabricationsApi = { + list: (params?: { type?: string; statut?: string; jardin_id?: number }) => + client.get('/api/fabrications', { params }).then(r => r.data), + get: (id: number) => client.get(`/api/fabrications/${id}`).then(r => r.data), + create: (f: Partial) => client.post('/api/fabrications', f).then(r => r.data), + update: (id: number, f: Partial) => client.put(`/api/fabrications/${id}`, f).then(r => r.data), + updateStatut: (id: number, statut: string) => client.patch(`/api/fabrications/${id}/statut`, { statut }).then(r => r.data), + delete: (id: number) => client.delete(`/api/fabrications/${id}`), +} diff --git a/frontend/src/stores/achats.ts b/frontend/src/stores/achats.ts new file mode 100644 index 0000000..52aa3c9 --- /dev/null +++ b/frontend/src/stores/achats.ts @@ -0,0 +1,28 @@ +// frontend/src/stores/achats.ts +import { defineStore } from 'pinia' +import { ref } from 'vue' +import { achatsApi, type AchatIntrant } from '@/api/achats' + +export const useAchatsStore = defineStore('achats', () => { + const achats = ref([]) + const loading = ref(false) + + async function fetchAll(params?: { categorie?: string }) { + loading.value = true + try { achats.value = await achatsApi.list(params) } + finally { loading.value = false } + } + + async function create(a: Partial) { + const created = await achatsApi.create(a) + achats.value.unshift(created) + return created + } + + async function remove(id: number) { + await achatsApi.delete(id) + achats.value = achats.value.filter(a => a.id !== id) + } + + return { achats, loading, fetchAll, create, remove } +}) diff --git a/frontend/src/stores/fabrications.ts b/frontend/src/stores/fabrications.ts new file mode 100644 index 0000000..1e4ec44 --- /dev/null +++ b/frontend/src/stores/fabrications.ts @@ -0,0 +1,35 @@ +// frontend/src/stores/fabrications.ts +import { defineStore } from 'pinia' +import { ref } from 'vue' +import { fabricationsApi, type Fabrication } from '@/api/fabrications' + +export const useFabricationsStore = defineStore('fabrications', () => { + const fabrications = ref([]) + const loading = ref(false) + + async function fetchAll(params?: { type?: string; statut?: string }) { + loading.value = true + try { fabrications.value = await fabricationsApi.list(params) } + finally { loading.value = false } + } + + async function create(f: Partial) { + const created = await fabricationsApi.create(f) + fabrications.value.unshift(created) + return created + } + + async function updateStatut(id: number, statut: string) { + const updated = await fabricationsApi.updateStatut(id, statut) + const idx = fabrications.value.findIndex(f => f.id === id) + if (idx !== -1) fabrications.value[idx] = updated + return updated + } + + async function remove(id: number) { + await fabricationsApi.delete(id) + fabrications.value = fabrications.value.filter(f => f.id !== id) + } + + return { fabrications, loading, fetchAll, create, updateStatut, remove } +})