feat : add Project DTO and service (frontend)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
17
frontend/services/dto/project.ts
Normal file
17
frontend/services/dto/project.ts
Normal 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
|
||||
}
|
||||
32
frontend/services/projects.ts
Normal file
32
frontend/services/projects.ts
Normal 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 }
|
||||
}
|
||||
Reference in New Issue
Block a user