You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
865 B
35 lines
865 B
|
2 years ago
|
import { Injectable } from '@angular/core';
|
||
|
|
import { HttpClient } from "@angular/common/http";
|
||
|
|
import { Observable, from } from "rxjs";
|
||
|
|
|
||
|
|
import { Season } from '../models/season.model';
|
||
|
|
|
||
|
|
@Injectable({
|
||
|
|
providedIn: 'root'
|
||
|
|
})
|
||
|
|
|
||
|
|
export class SeasonsService {
|
||
|
|
seasons: Season[] = [];
|
||
|
|
|
||
|
|
constructor(private httpClient: HttpClient) {
|
||
|
|
}
|
||
|
|
|
||
|
|
getAllSeasons(): Observable<Array<Season>> {
|
||
|
|
return this.httpClient.get<Array<Season>>("assets/Seasons.json")
|
||
|
|
}
|
||
|
|
|
||
|
|
getSeason(id: string): Observable<Season | undefined> {
|
||
|
|
let promise = new Promise<Season|undefined>((resolve, reject) =>{
|
||
|
|
this.httpClient.get<Array<Season>>("assets/Seasons.json").subscribe(data => {
|
||
|
|
for(let season of data) {
|
||
|
|
if(season.id == id) {
|
||
|
|
resolve(season);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
reject(undefined);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
return from(promise);
|
||
|
|
}
|
||
|
|
}
|