import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Lore, LoreCreate, LoreNode, LoreNodeCreate } from './lore.model'; /** * Service HTTP pour la gestion des Lores. * Port de sortie vers le Backend Java (Architecture Hexagonale). */ @Injectable({ providedIn: 'root' }) export class LoreService { private apiUrl = 'http://localhost:8080/api/lores'; private nodesUrl = 'http://localhost:8080/api/lore-nodes'; constructor(private http: HttpClient) {} getAllLores(): Observable { return this.http.get(this.apiUrl); } getLoreById(id: string): Observable { return this.http.get(`${this.apiUrl}/${id}`); } createLore(lore: LoreCreate): Observable { return this.http.post(this.apiUrl, lore); } updateLore(id: string, lore: LoreCreate): Observable { return this.http.put(`${this.apiUrl}/${id}`, lore); } deleteLore(id: string): Observable { return this.http.delete(`${this.apiUrl}/${id}`); } getLoreNodes(loreId: string): Observable { return this.http.get(`${this.nodesUrl}?loreId=${loreId}`); } getLoreNodeById(id: string): Observable { return this.http.get(`${this.nodesUrl}/${id}`); } createLoreNode(node: LoreNodeCreate): Observable { return this.http.post(this.nodesUrl, node); } /** PUT complet — envoie l'objet entier au backend (qui attend un LoreNodeDTO). */ updateLoreNode(id: string, node: LoreNode): Observable { return this.http.put(`${this.nodesUrl}/${id}`, node); } deleteLoreNode(id: string): Observable { return this.http.delete(`${this.nodesUrl}/${id}`); } searchLores(q: string): Observable { const params = new HttpParams().set('q', q); return this.http.get(`${this.apiUrl}/search`, { params }); } searchLoreNodes(q: string): Observable { const params = new HttpParams().set('q', q); return this.http.get(`${this.nodesUrl}/search`, { params }); } }