Services: add genre service

This commit is contained in:
Toast 2025-02-07 18:53:29 +01:00
parent 70f7738966
commit d7c9e892d4
2 changed files with 56 additions and 0 deletions

View file

@ -0,0 +1,16 @@
import {TestBed} from '@angular/core/testing';
import {GenresService} from './genres.service';
describe('GenresService', () => {
let service: GenresService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(GenresService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View file

@ -0,0 +1,40 @@
import {inject, Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {ApiResponse} from '../../interfaces/api-response';
import {ApiIdResponse} from '../../interfaces/api-id-response';
import {Show} from '../../interfaces/show';
import {ApiCreationResponse} from '../../interfaces/api-creation-response';
import {ApiDeletionEditResponse} from '../../interfaces/api-deletion-edit-response';
@Injectable({
providedIn: 'root'
})
export class GenresService {
private readonly url: string = "https://shows.everest.tailscale/api/";
private genresEndpoint: string
private idEndpoint: string
private http: HttpClient = inject(HttpClient);
constructor() {
this.genresEndpoint = this.url + "genres/"
this.idEndpoint = this.genresEndpoint + "id/"
}
getGenres(): Observable<ApiResponse> {
return this.http.get<ApiResponse>(this.genresEndpoint)
}
getGenre(id: string): Observable<ApiIdResponse> {
return this.http.get<ApiIdResponse>(this.idEndpoint + id)
}
sendGenre(newShow: Show): Observable<ApiCreationResponse> {
return this.http.post<ApiCreationResponse>(this.genresEndpoint, newShow)
}
updateGenre(show: Show): Observable<ApiDeletionEditResponse> {
return this.http.put<ApiDeletionEditResponse>(this.idEndpoint + show._id, show)
}
}