Add shows api service
This commit is contained in:
parent
edbd84845a
commit
5cf778e390
4 changed files with 61 additions and 4 deletions
|
|
@ -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())
|
||||
]
|
||||
};
|
||||
|
|
|
|||
16
src/shows/shows-api.service.spec.ts
Normal file
16
src/shows/shows-api.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
22
src/shows/shows-api.service.ts
Normal file
22
src/shows/shows-api.service.ts
Normal 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
14
src/shows/shows-api.ts
Normal 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[]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue