avant codex
This commit is contained in:
@@ -18,10 +18,17 @@ export const useGardensStore = defineStore('gardens', () => {
|
||||
return created
|
||||
}
|
||||
|
||||
async function update(id: number, g: Partial<Garden>) {
|
||||
const updated = await gardensApi.update(id, g)
|
||||
const idx = gardens.value.findIndex(x => x.id === id)
|
||||
if (idx !== -1) gardens.value[idx] = updated
|
||||
return updated
|
||||
}
|
||||
|
||||
async function remove(id: number) {
|
||||
await gardensApi.delete(id)
|
||||
gardens.value = gardens.value.filter(g => g.id !== id)
|
||||
}
|
||||
|
||||
return { gardens, loading, fetchAll, create, remove }
|
||||
return { gardens, loading, fetchAll, create, update, remove }
|
||||
})
|
||||
|
||||
@@ -18,10 +18,17 @@ export const usePlantingsStore = defineStore('plantings', () => {
|
||||
return created
|
||||
}
|
||||
|
||||
async function update(id: number, p: Partial<Planting>) {
|
||||
const updated = await plantingsApi.update(id, p)
|
||||
const idx = plantings.value.findIndex(x => x.id === id)
|
||||
if (idx !== -1) plantings.value[idx] = updated
|
||||
return updated
|
||||
}
|
||||
|
||||
async function remove(id: number) {
|
||||
await plantingsApi.delete(id)
|
||||
plantings.value = plantings.value.filter(p => p.id !== id)
|
||||
}
|
||||
|
||||
return { plantings, loading, fetchAll, create, remove }
|
||||
return { plantings, loading, fetchAll, create, update, remove }
|
||||
})
|
||||
|
||||
26
frontend/src/stores/plants.js
Normal file
26
frontend/src/stores/plants.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { plantsApi } from '@/api/plants';
|
||||
export const usePlantsStore = defineStore('plants', () => {
|
||||
const plants = ref([]);
|
||||
const loading = ref(false);
|
||||
async function fetchAll(categorie) {
|
||||
loading.value = true;
|
||||
try {
|
||||
plants.value = await plantsApi.list(categorie);
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
async function create(p) {
|
||||
const created = await plantsApi.create(p);
|
||||
plants.value.push(created);
|
||||
return created;
|
||||
}
|
||||
async function remove(id) {
|
||||
await plantsApi.delete(id);
|
||||
plants.value = plants.value.filter(p => p.id !== id);
|
||||
}
|
||||
return { plants, loading, fetchAll, create, remove };
|
||||
});
|
||||
27
frontend/src/stores/plants.ts
Normal file
27
frontend/src/stores/plants.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { plantsApi, type Plant } from '@/api/plants'
|
||||
|
||||
export const usePlantsStore = defineStore('plants', () => {
|
||||
const plants = ref<Plant[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
async function fetchAll(categorie?: string) {
|
||||
loading.value = true
|
||||
try { plants.value = await plantsApi.list(categorie) }
|
||||
finally { loading.value = false }
|
||||
}
|
||||
|
||||
async function create(p: Partial<Plant>) {
|
||||
const created = await plantsApi.create(p)
|
||||
plants.value.push(created)
|
||||
return created
|
||||
}
|
||||
|
||||
async function remove(id: number) {
|
||||
await plantsApi.delete(id)
|
||||
plants.value = plants.value.filter(p => p.id !== id)
|
||||
}
|
||||
|
||||
return { plants, loading, fetchAll, create, remove }
|
||||
})
|
||||
@@ -18,6 +18,13 @@ export const useTasksStore = defineStore('tasks', () => {
|
||||
return created
|
||||
}
|
||||
|
||||
async function update(id: number, data: Partial<Task>) {
|
||||
const updated = await tasksApi.update(id, data)
|
||||
const idx = tasks.value.findIndex(t => t.id === id)
|
||||
if (idx !== -1) tasks.value[idx] = updated
|
||||
return updated
|
||||
}
|
||||
|
||||
async function updateStatut(id: number, statut: string) {
|
||||
const t = tasks.value.find(t => t.id === id)
|
||||
if (!t) return
|
||||
@@ -30,5 +37,5 @@ export const useTasksStore = defineStore('tasks', () => {
|
||||
tasks.value = tasks.value.filter(t => t.id !== id)
|
||||
}
|
||||
|
||||
return { tasks, loading, fetchAll, create, updateStatut, remove }
|
||||
return { tasks, loading, fetchAll, create, update, updateStatut, remove }
|
||||
})
|
||||
|
||||
26
frontend/src/stores/tools.js
Normal file
26
frontend/src/stores/tools.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import { toolsApi } from '@/api/tools';
|
||||
export const useToolsStore = defineStore('tools', () => {
|
||||
const tools = ref([]);
|
||||
const loading = ref(false);
|
||||
async function fetchAll() {
|
||||
loading.value = true;
|
||||
try {
|
||||
tools.value = await toolsApi.list();
|
||||
}
|
||||
finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
async function create(t) {
|
||||
const created = await toolsApi.create(t);
|
||||
tools.value.push(created);
|
||||
return created;
|
||||
}
|
||||
async function remove(id) {
|
||||
await toolsApi.delete(id);
|
||||
tools.value = tools.value.filter(t => t.id !== id);
|
||||
}
|
||||
return { tools, loading, fetchAll, create, remove };
|
||||
});
|
||||
34
frontend/src/stores/tools.ts
Normal file
34
frontend/src/stores/tools.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { toolsApi, type Tool } from '@/api/tools'
|
||||
|
||||
export const useToolsStore = defineStore('tools', () => {
|
||||
const tools = ref<Tool[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
async function fetchAll() {
|
||||
loading.value = true
|
||||
try { tools.value = await toolsApi.list() }
|
||||
finally { loading.value = false }
|
||||
}
|
||||
|
||||
async function create(t: Partial<Tool>) {
|
||||
const created = await toolsApi.create(t)
|
||||
tools.value.push(created)
|
||||
return created
|
||||
}
|
||||
|
||||
async function update(id: number, t: Partial<Tool>) {
|
||||
const updated = await toolsApi.update(id, t)
|
||||
const idx = tools.value.findIndex(x => x.id === id)
|
||||
if (idx !== -1) tools.value[idx] = updated
|
||||
return updated
|
||||
}
|
||||
|
||||
async function remove(id: number) {
|
||||
await toolsApi.delete(id)
|
||||
tools.value = tools.value.filter(t => t.id !== id)
|
||||
}
|
||||
|
||||
return { tools, loading, fetchAll, create, update, remove }
|
||||
})
|
||||
Reference in New Issue
Block a user