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.
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create(title: string, subTitle: string, startingDate: Date) {
|
|
|
|
|
return this.httpClient.post("http://localhost:3000/seasons/", {title, subTitle, startingDate});
|
|
|
|
|
}
|
|
|
|
|
}
|