From 9aa45d28d8c8e5f6c5eb25e67fbe40ef21a6c0e0 Mon Sep 17 00:00:00 2001 From: kevinpauer Date: Wed, 23 Mar 2022 19:07:56 +0100 Subject: [PATCH] Add stock data api call --- frontend/src/app/Services/data.service.ts | 32 +++++++++++-------- .../Views/dashboard/dashboard.component.ts | 8 +++-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/frontend/src/app/Services/data.service.ts b/frontend/src/app/Services/data.service.ts index 45e6617..4419d9f 100644 --- a/frontend/src/app/Services/data.service.ts +++ b/frontend/src/app/Services/data.service.ts @@ -12,21 +12,27 @@ export class DataService { private tokenStorage: TokenStorageService ) {} - httpOptions = { - headers: new HttpHeaders({ - 'Content-Type': 'application/json', - Authorization: 'Bearer' + this.tokenStorage.getToken(), - }), - }; + headers = new HttpHeaders({ + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + this.tokenStorage.getToken(), + }); - getStockData(): Observable { - return this.http.get(API_URL + 'portfolio', { - headers: this.httpOptions.headers, + async getStockData() { + await this.http + .get(API_URL + 'portfolio', { + headers: this.headers, + responseType: 'text', + }) + .subscribe((data) => { + console.log(data); + return data; + }); + } + + getKeywords(): Observable { + return this.http.get(API_URL + 'keywords', { + headers: this.headers, responseType: 'text', }); } - - showStorage() { - console.log(localStorage); - } } diff --git a/frontend/src/app/Views/dashboard/dashboard.component.ts b/frontend/src/app/Views/dashboard/dashboard.component.ts index 5752606..ecc7a4b 100644 --- a/frontend/src/app/Views/dashboard/dashboard.component.ts +++ b/frontend/src/app/Views/dashboard/dashboard.component.ts @@ -1,4 +1,6 @@ import { Component, OnInit } from '@angular/core'; +import { throwToolbarMixedModesError } from '@angular/material/toolbar'; +import { DataService } from 'src/app/Services/data.service'; export interface PeriodicElement { name: string; @@ -46,9 +48,11 @@ const ELEMENT_DATA: PeriodicElement[] = [ styleUrls: ['./dashboard.component.scss'], }) export class DashboardComponent implements OnInit { - constructor() {} + constructor(private dataService: DataService) {} - ngOnInit(): void {} + async ngOnInit() { + const data = await this.dataService.getStockData(); + } displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; dataSource = ELEMENT_DATA;