initial commit
This commit is contained in:
111
docs/architecture/5-api-specification.md
Normal file
111
docs/architecture/5-api-specification.md
Normal file
@@ -0,0 +1,111 @@
|
||||
# 5. API Specification
|
||||
|
||||
## Server Functions Pattern
|
||||
|
||||
TanStack Start utilise des "Server Functions" - des fonctions RPC type-safe qui s'exécutent côté serveur.
|
||||
|
||||
```typescript
|
||||
// Définition
|
||||
import { createServerFn } from '@tanstack/react-start/server';
|
||||
import { z } from 'zod';
|
||||
|
||||
const inputSchema = z.object({
|
||||
name: z.string().min(1),
|
||||
});
|
||||
|
||||
export const createCharacter = createServerFn({ method: 'POST' })
|
||||
.validator((data: unknown) => inputSchema.parse(data))
|
||||
.handler(async ({ data }) => {
|
||||
// Logique serveur avec accès DB
|
||||
return await db.character.create({ data });
|
||||
});
|
||||
|
||||
// Utilisation côté client
|
||||
const result = await createCharacter({ data: { name: 'MyChar' } });
|
||||
```
|
||||
|
||||
## API Endpoints (Server Functions)
|
||||
|
||||
### Characters
|
||||
|
||||
| Function | Method | Description |
|
||||
|----------|--------|-------------|
|
||||
| `getCharacters` | GET | Liste tous les personnages avec filtres |
|
||||
| `getCharacter` | GET | Récupère un personnage par ID |
|
||||
| `createCharacter` | POST | Crée un nouveau personnage |
|
||||
| `updateCharacter` | POST | Met à jour un personnage |
|
||||
| `deleteCharacter` | POST | Supprime un personnage |
|
||||
| `bulkUpdateCharacters` | POST | Met à jour plusieurs personnages |
|
||||
| `bulkDeleteCharacters` | POST | Supprime plusieurs personnages |
|
||||
|
||||
### Accounts
|
||||
|
||||
| Function | Method | Description |
|
||||
|----------|--------|-------------|
|
||||
| `getAccounts` | GET | Liste tous les comptes |
|
||||
| `getAccount` | GET | Récupère un compte par ID |
|
||||
| `createAccount` | POST | Crée un nouveau compte |
|
||||
| `updateAccount` | POST | Met à jour un compte |
|
||||
| `deleteAccount` | POST | Supprime un compte |
|
||||
|
||||
### Teams
|
||||
|
||||
| Function | Method | Description |
|
||||
|----------|--------|-------------|
|
||||
| `getTeams` | GET | Liste toutes les équipes |
|
||||
| `getTeam` | GET | Récupère une équipe avec ses membres |
|
||||
| `createTeam` | POST | Crée une nouvelle équipe |
|
||||
| `updateTeam` | POST | Met à jour une équipe |
|
||||
| `deleteTeam` | POST | Supprime une équipe |
|
||||
| `addTeamMembers` | POST | Ajoute des personnages à une équipe |
|
||||
| `removeTeamMembers` | POST | Retire des personnages d'une équipe |
|
||||
|
||||
### Progressions
|
||||
|
||||
| Function | Method | Description |
|
||||
|----------|--------|-------------|
|
||||
| `getProgressions` | GET | Liste toutes les progressions |
|
||||
| `getCharacterProgressions` | GET | Progressions d'un personnage |
|
||||
| `updateCharacterProgression` | POST | Met à jour une progression |
|
||||
| `bulkUpdateProgressions` | POST | Met à jour plusieurs progressions |
|
||||
| `syncFromDofusDb` | POST | Synchronise depuis DofusDB |
|
||||
|
||||
### Auth
|
||||
|
||||
| Function | Method | Description |
|
||||
|----------|--------|-------------|
|
||||
| `login` | POST | Authentification |
|
||||
| `logout` | POST | Déconnexion |
|
||||
| `getSession` | GET | Récupère la session courante |
|
||||
|
||||
## Validation Schemas
|
||||
|
||||
```typescript
|
||||
// src/lib/schemas/character.ts
|
||||
import { z } from 'zod';
|
||||
|
||||
export const createCharacterSchema = z.object({
|
||||
name: z.string().min(2).max(50),
|
||||
level: z.number().int().min(1).max(200),
|
||||
classId: z.number().int().positive(),
|
||||
serverId: z.number().int().positive(),
|
||||
accountId: z.string().uuid(),
|
||||
});
|
||||
|
||||
export const updateCharacterSchema = createCharacterSchema.partial();
|
||||
|
||||
export const characterFiltersSchema = z.object({
|
||||
search: z.string().optional(),
|
||||
classIds: z.array(z.number()).optional(),
|
||||
serverIds: z.array(z.number()).optional(),
|
||||
accountIds: z.array(z.string()).optional(),
|
||||
minLevel: z.number().optional(),
|
||||
maxLevel: z.number().optional(),
|
||||
page: z.number().int().positive().default(1),
|
||||
limit: z.number().int().min(1).max(100).default(20),
|
||||
sortBy: z.enum(['name', 'level', 'class', 'server']).default('name'),
|
||||
sortOrder: z.enum(['asc', 'desc']).default('asc'),
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
Reference in New Issue
Block a user