Files
kmtnflower/src/app/services/history-entry.service.ts
T
2026-06-21 05:24:40 +00:00

38 lines
1.3 KiB
TypeScript

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<HistoryEntry[]> {
let params = new HttpParams();
if (active !== undefined) params = params.set('active', String(active));
return this.http.get<HistoryEntry[]>(this.baseUrl, { params });
}
getHistoryEntry(id: number): Observable<HistoryEntry> {
return this.http.get<HistoryEntry>(`${this.baseUrl}/${id}`);
}
createHistoryEntry(payload: Omit<HistoryEntry, 'id'>): Observable<HistoryEntry> {
return this.http.post<HistoryEntry>(this.baseUrl, payload);
}
updateHistoryEntry(id: number, payload: Partial<HistoryEntry>): Observable<HistoryEntry> {
return this.http.put<HistoryEntry>(`${this.baseUrl}/${id}`, payload);
}
deleteHistoryEntry(id: number): Observable<void> {
return this.http.delete<void>(`${this.baseUrl}/${id}`);
}
}