import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; import { ApiService } from './api.service'; import { AuthService } from './auth.service'; // Interfaccia per i dati dell'insegnante export interface Teacher { id: number; first_name: string; last_name: string; email?: string | null; phone?: string | null; date_of_birth?: string | null; // Manteniamo stringa per semplicità, potremmo usare Date hire_date?: string | null; qualifications?: string | null; is_active: boolean; // O number se il backend restituisce 0/1 created_at: string; updated_at: string; } // Interfaccia per i dati parziali usati in creazione/modifica export type TeacherInput = Partial>; @Injectable({ providedIn: 'root' }) export class TeacherService extends ApiService { constructor(authService: AuthService, http: HttpClient) { super(authService, http, 'teachers'); } // GET /api/teachers getTeachers(): Observable { // Il backend restituisce già un array ridotto per la lista return this.get(`${this.controllerName}`); } // GET /api/teachers/{id} getTeacher(id: number): Observable { return this.get(`${this.controllerName}/${id}`); } // POST /api/teachers addTeacher(teacher: TeacherInput): Observable { return this.post(`${this.controllerName}`, teacher); } // PUT /api/teachers/{id} updateTeacher(id: number, teacher: TeacherInput): Observable { return this.put(`${this.controllerName}/${id}`, teacher); } // DELETE /api/teachers/{id} deleteTeacher(id: number): Observable { return this.delete(`${this.controllerName}/${id}`); } }