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.
40 lines
1.1 KiB
40 lines
1.1 KiB
import { Injectable } from '@angular/core'
|
|
import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams, HttpRequest } from '@angular/common/http'
|
|
import { Observable, Subject, throwError } from 'rxjs'
|
|
import { catchError, retry } from 'rxjs/operators'
|
|
import { environment } from '../environments/environment'
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
|
|
export class StationService {
|
|
|
|
private restApi = `${environment.API_URL}`
|
|
|
|
constructor(
|
|
private http: HttpClient
|
|
) { }
|
|
|
|
commonHeaders(): any {
|
|
return new HttpHeaders({
|
|
//'Authorization': `Bearer ${sessionStorage.getItem('auth_token')}`
|
|
})
|
|
}
|
|
|
|
protected handleError(error: HttpErrorResponse) {
|
|
if(error.error instanceof ErrorEvent) {
|
|
console.error('An error occurred:', error.error.message)
|
|
}
|
|
return throwError(error)
|
|
}
|
|
|
|
|
|
getData(day: string, spot: string): Observable<any> {
|
|
const apiUrl = `${this.restApi}/get_data?day=${day}&spot=${spot}`;
|
|
return this.http.get<any>(apiUrl, {headers: this.commonHeaders()}).pipe(
|
|
catchError(this.handleError)
|
|
)
|
|
}
|
|
|
|
}
|