From 123bf2943ab42d2c7c0a56dc65adcadb088b8945 Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Tue, 4 Feb 2020 13:54:53 +0100 Subject: [PATCH] AW-811: Added weather service to common --- .../common/src/fm/common-service.module.ts | 2 ++ projects/common/src/fm/common.module.ts | 4 +++- .../fm/models/weatherCurrentObservation.ts | 13 +++++++++++ .../common/src/fm/services/weather.service.ts | 23 +++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 projects/common/src/fm/models/weatherCurrentObservation.ts create mode 100644 projects/common/src/fm/services/weather.service.ts diff --git a/projects/common/src/fm/common-service.module.ts b/projects/common/src/fm/common-service.module.ts index 30c8dfe..b4aa0bc 100644 --- a/projects/common/src/fm/common-service.module.ts +++ b/projects/common/src/fm/common-service.module.ts @@ -15,6 +15,7 @@ import { ItemService } from './services/item.service'; import { EventService } from './services/event.service'; import { TypeaheadService } from './services/typeahead.service'; import { UserService } from './services/user.service'; +import { WeatherService} from './services/weather.service'; import { AppConfig } from './shared/app.config'; import { AccessTokenInterceptor } from "./shared/accesstoken.interceptor"; import { appConfigFactory } from "./shared/app.config.factory"; @@ -35,6 +36,7 @@ export { EventService, TypeaheadService, UserService, + WeatherService, CodeListItemService, AppConfig, AccessTokenInterceptor, diff --git a/projects/common/src/fm/common.module.ts b/projects/common/src/fm/common.module.ts index 3884af7..ec5beb5 100644 --- a/projects/common/src/fm/common.module.ts +++ b/projects/common/src/fm/common.module.ts @@ -32,6 +32,7 @@ import { TagInputComponent } from './components/tag-input/tag-input.component'; import { MenuBackgroundComponent } from './components/menu-background/menu-background.component'; import { IEventMessage } from './models/event.message'; import { IItem, Item } from './models/item'; +import { WeatherCurrentObservation } from './models/weatherCurrentObservation'; import { IItemType } from './models/item.type'; import { IItemTypes } from './models/item.types'; import { IItemTask, ItemTask } from './models/itemTask'; @@ -71,7 +72,8 @@ export { IAuthconfigFactory, AuthConfigFactory, MenuBackgroundComponent, - SecureOAuthStorage + SecureOAuthStorage, + WeatherCurrentObservation }; @NgModule({ diff --git a/projects/common/src/fm/models/weatherCurrentObservation.ts b/projects/common/src/fm/models/weatherCurrentObservation.ts new file mode 100644 index 0000000..fd26d9c --- /dev/null +++ b/projects/common/src/fm/models/weatherCurrentObservation.ts @@ -0,0 +1,13 @@ +export interface WeatherCurrentObservation { + wspd: number; + obs_time_local: number; + decimal_temp: number; + rh: number; + precip_1hour: number; + precip_6hour: number; + precip_24hour: number; + uv_index: number; + icon_code: number; + wdir_cardinal: string; + wdir: number; +} diff --git a/projects/common/src/fm/services/weather.service.ts b/projects/common/src/fm/services/weather.service.ts new file mode 100644 index 0000000..1ecbacf --- /dev/null +++ b/projects/common/src/fm/services/weather.service.ts @@ -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 { + const endpoint = this.appConfig.getConfig('apiEndPoint'); + const observationUrl = `${endpoint}${this.apiUrl}/?c=${centroid[0]},${centroid[1]}&key=${this.apiKey}`; + + return this.httpClient.get(observationUrl); + } +}