AW-811: Added weather service to common
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
This commit is contained in:
23
projects/common/src/fm/services/weather.service.ts
Normal file
23
projects/common/src/fm/services/weather.service.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {AppConfig} from '../shared/app.config';
|
||||
import {Observable} from 'rxjs';
|
||||
import {WeatherCurrentObservation} from '../models/weatherCurrentObservation';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class WeatherService {
|
||||
private apiUrl = '/api/v1/weather/currentobservation';
|
||||
private apiKey = '5f17ef36283b49e9b099a1f4064fbf3d';
|
||||
|
||||
constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
|
||||
}
|
||||
|
||||
public GetCurrentObservation(centroid: number[]): Observable<WeatherCurrentObservation> {
|
||||
const endpoint = this.appConfig.getConfig('apiEndPoint');
|
||||
const observationUrl = `${endpoint}${this.apiUrl}/?c=${centroid[0]},${centroid[1]}&key=${this.apiKey}`;
|
||||
|
||||
return this.httpClient.get<WeatherCurrentObservation>(observationUrl);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user