import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Character, CharacterCreate } from './character.model'; /** Résultat de recherche d'un PJ, enrichi du campaignId pour la navigation. */ export interface CharacterSearchResult { id: string; name: string; playthroughId: string; campaignId: string; } /** * Service HTTP pour les fiches de personnages (PJ) d'une campagne. */ @Injectable({ providedIn: 'root' }) export class CharacterService { private apiUrl = '/api/characters'; constructor(private http: HttpClient) {} getByPlaythrough(playthroughId: string): Observable { return this.http.get(`${this.apiUrl}/playthrough/${playthroughId}`); } getById(id: string): Observable { return this.http.get(`${this.apiUrl}/${id}`); } create(payload: CharacterCreate): Observable { return this.http.post(this.apiUrl, payload); } update(id: string, payload: Character): Observable { return this.http.put(`${this.apiUrl}/${id}`, payload); } delete(id: string): Observable { return this.http.delete(`${this.apiUrl}/${id}`); } /** Recherche par nom — alimente la recherche globale (Ctrl+K). */ search(q: string): Observable { const params = new HttpParams().set('q', q); return this.http.get(`${this.apiUrl}/search`, { params }); } }