shows-admin/src/services/shows/shows-api.service.ts
2025-02-06 10:54:48 +01:00

44 lines
1.5 KiB
TypeScript

import {inject, Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {ShowsApiResponse} from '../../interfaces/shows-api-response';
import {ShowsApiCreation} from '../../interfaces/shows-api-creation';
import {ShowsApiIdResponse} from '../../interfaces/shows-api-id-response';
import {ShowsApiDeletionEdit} from '../../interfaces/shows-api-deletion-edit';
import {Show} from '../../interfaces/show';
@Injectable({
providedIn: 'root'
})
export class ShowsApiService {
private readonly url: string = "https://shows.everest.tailscale/api/";
private showsEndpoint: string
private idEndpoint: string
private http: HttpClient = inject(HttpClient);
constructor() {
this.showsEndpoint = this.url + "shows/"
this.idEndpoint = this.showsEndpoint + "id/"
}
getShows(): Observable<ShowsApiResponse> {
return this.http.get<ShowsApiResponse>(this.showsEndpoint)
}
getShow(id: string): Observable<ShowsApiIdResponse> {
return this.http.get<ShowsApiIdResponse>(this.idEndpoint + id)
}
sendShow(newShow: Show): Observable<ShowsApiCreation> {
return this.http.post<ShowsApiCreation>(this.showsEndpoint, newShow)
}
deleteShw(id: string): Observable<ShowsApiDeletionEdit> {
return this.http.delete<ShowsApiDeletionEdit>(this.idEndpoint + id)
}
updateShow(show: Show): Observable<ShowsApiDeletionEdit> {
return this.http.put<ShowsApiDeletionEdit>(this.idEndpoint + show._id, show)
}
}