38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { Injectable, inject } from '@angular/core';
|
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { CommunityHighlight } from '../interfaces/community-highlight';
|
|
import { getAppConfig } from './app-config.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class CommunityHighlightService {
|
|
private http = inject(HttpClient);
|
|
private baseUrl = `${getAppConfig().apiBaseUrl}/api/community`;
|
|
|
|
/** Fetch community highlights, optionally filtered by active status. */
|
|
getCommunityHighlights(active?: boolean): Observable<CommunityHighlight[]> {
|
|
let params = new HttpParams();
|
|
if (active !== undefined) params = params.set('active', String(active));
|
|
return this.http.get<CommunityHighlight[]>(this.baseUrl, { params });
|
|
}
|
|
|
|
getCommunityHighlight(id: number): Observable<CommunityHighlight> {
|
|
return this.http.get<CommunityHighlight>(`${this.baseUrl}/${id}`);
|
|
}
|
|
|
|
createCommunityHighlight(payload: Omit<CommunityHighlight, 'id'>): Observable<CommunityHighlight> {
|
|
return this.http.post<CommunityHighlight>(this.baseUrl, payload);
|
|
}
|
|
|
|
updateCommunityHighlight(id: number, payload: Partial<CommunityHighlight>): Observable<CommunityHighlight> {
|
|
return this.http.put<CommunityHighlight>(`${this.baseUrl}/${id}`, payload);
|
|
}
|
|
|
|
deleteCommunityHighlight(id: number): Observable<void> {
|
|
return this.http.delete<void>(`${this.baseUrl}/${id}`);
|
|
}
|
|
}
|