import { HttpClient, HttpParams } from '@angular/common/http'; import { Injectable, inject } from '@angular/core'; import { Observable } from 'rxjs'; import { environment } from '../../environments/environment'; export type StatoCategoria = 'confermata' | 'da_approvare'; export interface Categoria { id: string; nome: string; stato: StatoCategoria; creatoDaOrgId: string | null; creatoIl: string; } @Injectable({ providedIn: 'root' }) export class CategorieApiService { private readonly http = inject(HttpClient); getCategorie(): Observable { return this.http.get(`${environment.magazzinoApiBaseUrl}/categorie`); } getCategoriePubbliche(nome?: string): Observable { const params = nome ? new HttpParams().set('nome', nome) : undefined; return this.http.get(`${environment.magazzinoApiBaseUrl}/categorie/pubbliche`, { params }); } creaCategoria(nome: string): Observable { return this.http.post(`${environment.magazzinoApiBaseUrl}/categorie`, { nome }); } aggiornaCategoria(id: string, nome: string): Observable { return this.http.put(`${environment.magazzinoApiBaseUrl}/categorie/${id}`, { nome }); } eliminaCategoria(id: string): Observable { return this.http.delete(`${environment.magazzinoApiBaseUrl}/categorie/${id}`); } proponiCategoria(nome: string): Observable { return this.http.post(`${environment.magazzinoApiBaseUrl}/categorie/proposte`, { nome }); } approvaCategoria(id: string): Observable { return this.http.post(`${environment.magazzinoApiBaseUrl}/categorie/${id}/approva`, {}); } rifiutaCategoria(id: string): Observable { return this.http.post(`${environment.magazzinoApiBaseUrl}/categorie/${id}/rifiuta`, {}); } }