import { Injectable, inject } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; import { HistoryEntry } from '../interfaces/history-entry'; import { getAppConfig } from './app-config.service'; @Injectable({ providedIn: 'root', }) export class HistoryEntryService { private http = inject(HttpClient); private baseUrl = `${getAppConfig().apiBaseUrl}/api/history`; /** Fetch history entries, optionally filtered by active status. */ getHistoryEntries(active?: boolean): Observable { let params = new HttpParams(); if (active !== undefined) params = params.set('active', String(active)); return this.http.get(this.baseUrl, { params }); } getHistoryEntry(id: number): Observable { return this.http.get(`${this.baseUrl}/${id}`); } createHistoryEntry(payload: Omit): Observable { return this.http.post(this.baseUrl, payload); } updateHistoryEntry(id: number, payload: Partial): Observable { return this.http.put(`${this.baseUrl}/${id}`, payload); } deleteHistoryEntry(id: number): Observable { return this.http.delete(`${this.baseUrl}/${id}`); } }