import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Entry, CreateEntryDto, UpdateEntryDto, ImportResult } from '../models'; @Injectable({ providedIn: 'root' }) export class EntryService { constructor(private http: HttpClient) {} getEntries(monthId: string): Observable { return this.http.get(`/api/months/${monthId}/entries`); } createEntry(monthId: string, dto: CreateEntryDto): Observable { return this.http.post(`/api/months/${monthId}/entries`, dto); } updateEntry(id: string, dto: UpdateEntryDto): Observable { return this.http.put(`/api/entries/${id}`, dto); } deleteEntry(id: string): Observable { return this.http.delete(`/api/entries/${id}`); } importCsv(monthId: string, file: File): Observable { const formData = new FormData(); formData.append('file', file); return this.http.post(`/api/months/${monthId}/entries/import`, formData); } exportExcel(monthId: string, fileName: string): Observable { return this.http.get(`/api/months/${monthId}/entries/export?fileName=${encodeURIComponent(fileName)}`, { responseType: 'blob', }); } }