feat(frontend): API layer + stores Pinia

Ajoute le client Axios, les modules API (gardens, varieties, plantings,
tasks) et les stores Pinia correspondants. Corrige tsconfig.json pour
inclure vite/client et DOM.Iterable.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 04:10:16 +01:00
parent b8edb6bc0a
commit f29f90a16f
10 changed files with 245 additions and 1 deletions

View File

@@ -0,0 +1,27 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { gardensApi, type Garden } from '@/api/gardens'
export const useGardensStore = defineStore('gardens', () => {
const gardens = ref<Garden[]>([])
const loading = ref(false)
async function fetchAll() {
loading.value = true
gardens.value = await gardensApi.list()
loading.value = false
}
async function create(g: Partial<Garden>) {
const created = await gardensApi.create(g)
gardens.value.push(created)
return created
}
async function remove(id: number) {
await gardensApi.delete(id)
gardens.value = gardens.value.filter(g => g.id !== id)
}
return { gardens, loading, fetchAll, create, remove }
})

View File

@@ -0,0 +1,27 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { plantingsApi, type Planting } from '@/api/plantings'
export const usePlantingsStore = defineStore('plantings', () => {
const plantings = ref<Planting[]>([])
const loading = ref(false)
async function fetchAll() {
loading.value = true
plantings.value = await plantingsApi.list()
loading.value = false
}
async function create(p: Partial<Planting>) {
const created = await plantingsApi.create(p)
plantings.value.push(created)
return created
}
async function remove(id: number) {
await plantingsApi.delete(id)
plantings.value = plantings.value.filter(p => p.id !== id)
}
return { plantings, loading, fetchAll, create, remove }
})

View File

@@ -0,0 +1,34 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { tasksApi, type Task } from '@/api/tasks'
export const useTasksStore = defineStore('tasks', () => {
const tasks = ref<Task[]>([])
const loading = ref(false)
async function fetchAll(params?: { statut?: string; garden_id?: number }) {
loading.value = true
tasks.value = await tasksApi.list(params)
loading.value = false
}
async function create(t: Partial<Task>) {
const created = await tasksApi.create(t)
tasks.value.push(created)
return created
}
async function updateStatut(id: number, statut: string) {
const t = tasks.value.find(t => t.id === id)
if (!t) return
const updated = await tasksApi.update(id, { ...t, statut })
Object.assign(t, updated)
}
async function remove(id: number) {
await tasksApi.delete(id)
tasks.value = tasks.value.filter(t => t.id !== id)
}
return { tasks, loading, fetchAll, create, updateStatut, remove }
})

View File

@@ -0,0 +1,27 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { varietiesApi, type PlantVariety } from '@/api/varieties'
export const useVarietiesStore = defineStore('varieties', () => {
const varieties = ref<PlantVariety[]>([])
const loading = ref(false)
async function fetchAll() {
loading.value = true
varieties.value = await varietiesApi.list()
loading.value = false
}
async function create(v: Partial<PlantVariety>) {
const created = await varietiesApi.create(v)
varieties.value.push(created)
return created
}
async function remove(id: number) {
await varietiesApi.delete(id)
varieties.value = varieties.value.filter(v => v.id !== id)
}
return { varieties, loading, fetchAll, create, remove }
})