working 3 tier approach
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
import { Event } from '../interfaces/event';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class EventService {
|
||||
private http = inject(HttpClient);
|
||||
private baseUrl = `${environment.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}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
import { Program } from '../interfaces/program';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ProgramService {
|
||||
private http = inject(HttpClient);
|
||||
private baseUrl = `${environment.apiBaseUrl}/api/programs`;
|
||||
|
||||
/** Fetch all programs, optionally filtered by day_of_week (1=Mon … 7=Sun). */
|
||||
getPrograms(day?: number): Observable<Program[]> {
|
||||
let params = new HttpParams();
|
||||
if (day !== undefined) params = params.set('day', String(day));
|
||||
return this.http.get<Program[]>(this.baseUrl, { params });
|
||||
}
|
||||
|
||||
getProgram(id: number): Observable<Program> {
|
||||
return this.http.get<Program>(`${this.baseUrl}/${id}`);
|
||||
}
|
||||
|
||||
createProgram(payload: Omit<Program, 'id'>): Observable<Program> {
|
||||
return this.http.post<Program>(this.baseUrl, payload);
|
||||
}
|
||||
|
||||
updateProgram(id: number, payload: Partial<Program>): Observable<Program> {
|
||||
return this.http.put<Program>(`${this.baseUrl}/${id}`, payload);
|
||||
}
|
||||
|
||||
deleteProgram(id: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.baseUrl}/${id}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
import { Tier } from '../interfaces/tier';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class TierService {
|
||||
private http = inject(HttpClient);
|
||||
private baseUrl = `${environment.apiBaseUrl}/api/tiers`;
|
||||
|
||||
/** Fetch all tiers ordered by display_order. */
|
||||
getTiers(): Observable<Tier[]> {
|
||||
return this.http.get<Tier[]>(this.baseUrl);
|
||||
}
|
||||
|
||||
getTier(id: number): Observable<Tier> {
|
||||
return this.http.get<Tier>(`${this.baseUrl}/${id}`);
|
||||
}
|
||||
|
||||
createTier(payload: Omit<Tier, 'id'>): Observable<Tier> {
|
||||
return this.http.post<Tier>(this.baseUrl, payload);
|
||||
}
|
||||
|
||||
updateTier(id: number, payload: Partial<Tier>): Observable<Tier> {
|
||||
return this.http.put<Tier>(`${this.baseUrl}/${id}`, payload);
|
||||
}
|
||||
|
||||
deleteTier(id: number): Observable<void> {
|
||||
return this.http.delete<void>(`${this.baseUrl}/${id}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user