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.
41 lines
1.0 KiB
41 lines
1.0 KiB
2 years ago
|
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) {
|
||
|
this.layout = null
|
||
|
}
|
||
|
|
||
|
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): Observable<any> {
|
||
|
const apiUrl = `${this.restApi}/get_data?day=${day}`;
|
||
|
return this.http.get<any>(apiUrl, {headers: this.commonHeaders()}).pipe(
|
||
|
catchError(this.handleError)
|
||
|
)
|
||
|
}
|
||
|
|
||
|
}
|