feat : add Client DTO, service and Hydra utils (frontend)

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

View File

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

View File

@@ -0,0 +1,19 @@
export type Client = {
id: number
'@id'?: string
name: string
email: string | null
phone: string | null
street: string | null
city: string | null
postalCode: string | null
}
export type ClientWrite = {
name: string
email: string | null
phone: string | null
street: string | null
city: string | null
postalCode: string | null
}

8
frontend/utils/api.ts Normal file
View File

@@ -0,0 +1,8 @@
export type HydraCollection<T> = {
'hydra:member': T[]
'hydra:totalItems': number
}
export function extractHydraMembers<T>(response: HydraCollection<T>): T[] {
return response['hydra:member'] ?? []
}