feat : add Project DTO and service (frontend)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 22:43:14 +01:00
parent b5efb54f71
commit 5f57b377fa
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
import type { Client } from './client'
export type Project = {
id: number
'@id'?: string
name: string
description: string | null
color: string
client: Client | null
}
export type ProjectWrite = {
name: string
description: string | null
color: string
client: string | null // IRI : "/api/clients/1" ou null
}

View File

@@ -0,0 +1,32 @@
import type { Project, ProjectWrite } from './dto/project'
import type { HydraCollection } from '~/utils/api'
import { extractHydraMembers } from '~/utils/api'
export function useProjectService() {
const api = useApi()
async function getAll(): Promise<Project[]> {
const data = await api.get<HydraCollection<Project>>('/projects')
return extractHydraMembers(data)
}
async function create(payload: ProjectWrite): Promise<Project> {
return api.post<Project>('/projects', payload as Record<string, unknown>, {
toastSuccessKey: 'projects.created',
})
}
async function update(id: number, payload: Partial<ProjectWrite>): Promise<Project> {
return api.patch<Project>(`/projects/${id}`, payload as Record<string, unknown>, {
toastSuccessKey: 'projects.updated',
})
}
async function remove(id: number): Promise<void> {
await api.delete(`/projects/${id}`, {}, {
toastSuccessKey: 'projects.deleted',
})
}
return { getAll, create, update, remove }
}