Add shows api service

This commit is contained in:
Toast 2025-01-28 11:05:33 +01:00
parent edbd84845a
commit 5cf778e390
4 changed files with 61 additions and 4 deletions

View file

@ -1,8 +1,13 @@
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import {ApplicationConfig, provideZoneChangeDetection} from '@angular/core';
import {provideRouter} from '@angular/router';
import { routes } from './app.routes';
import {routes} from './app.routes';
import {provideHttpClient, withFetch} from '@angular/common/http';
export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes)]
providers: [
provideZoneChangeDetection({eventCoalescing: true}),
provideRouter(routes),
provideHttpClient(withFetch())
]
};

View file

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

View file

@ -0,0 +1,22 @@
import {inject, Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {ShowsApiResponse} from './shows-api';
@Injectable({
providedIn: 'root'
})
export class ShowsApiService {
private readonly url: string = "https://shows.everest.tailscale/api/";
private showsEndpoint: string
private http: HttpClient = inject(HttpClient);
constructor() {
this.showsEndpoint = this.url + "shows/"
}
getShows(): Observable<ShowsApiResponse> {
return this.http.get<ShowsApiResponse>(this.showsEndpoint)
}
}

14
src/shows/shows-api.ts Normal file
View file

@ -0,0 +1,14 @@
export interface ShowsApiResponse {
status: string
shows: Show[]
totalShows: number
}
export interface Show {
_id: string
title: string
year: number
seasons: number
description: string
genres: string[]
}