import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { ApiService } from './api.service'; import { AuthService } from './auth.service'; // Interfaccia per tipizzare i dati della struttura export interface Structure { id: number; name: string; address?: string | null; city?: string | null; province?: string | null; zip_code?: string | null; phone?: string | null; email?: string | null; notes?: string | null; created_at: string; // O Date se preferisci fare il parsing updated_at: string; // O Date } @Injectable({ providedIn: 'root' }) export class StructureService extends ApiService { constructor(authService: AuthService, http: HttpClient) { super(authService, http, 'structures'); } // GET /api/structures getStructures(): Observable { return this.get(`${this.controllerName}`); } // GET /api/structures/{id} getStructure(id: number): Observable { return this.get(`${this.controllerName}/${id}`); } // POST /api/structures addStructure(structure: Partial): Observable { return this.post(`${this.controllerName}`, structure); } // PUT /api/structures/{id} updateStructure(id: number, structure: Partial): Observable { return this.put(`${this.controllerName}/${id}`, structure); } // DELETE /api/structures/{id} deleteStructure(id: number): Observable { // DELETE restituisce 204 No Content // Specificare responseType: 'text' può aiutare se il backend non restituisce JSON valido su DELETE // ma dato che restituisce 204, Observable è appropriato. return this.delete(`${this.controllerName}/${id}`); } }