38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { Injectable, inject } from '@angular/core';
|
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { Event } from '../interfaces/event';
|
|
import { getAppConfig } from './app-config.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class EventService {
|
|
private http = inject(HttpClient);
|
|
private baseUrl = `${getAppConfig().apiBaseUrl}/api/events`;
|
|
|
|
/** Fetch events, optionally filtered by active status. */
|
|
getEvents(active?: boolean): Observable<Event[]> {
|
|
let params = new HttpParams();
|
|
if (active !== undefined) params = params.set('active', String(active));
|
|
return this.http.get<Event[]>(this.baseUrl, { params });
|
|
}
|
|
|
|
getEvent(id: number): Observable<Event> {
|
|
return this.http.get<Event>(`${this.baseUrl}/${id}`);
|
|
}
|
|
|
|
createEvent(payload: Omit<Event, 'id'>): Observable<Event> {
|
|
return this.http.post<Event>(this.baseUrl, payload);
|
|
}
|
|
|
|
updateEvent(id: number, payload: Partial<Event>): Observable<Event> {
|
|
return this.http.put<Event>(`${this.baseUrl}/${id}`, payload);
|
|
}
|
|
|
|
deleteEvent(id: number): Observable<void> {
|
|
return this.http.delete<void>(`${this.baseUrl}/${id}`);
|
|
}
|
|
}
|