From 16ad83ae404e5e35637ec9f10f72d33b0bbe7ead Mon Sep 17 00:00:00 2001 From: kevinpauer Date: Mon, 4 Apr 2022 23:13:02 +0200 Subject: [PATCH] Add data handling for transactions and stocks --- frontend/src/app/Helpers/helper.service.ts | 6 +- frontend/src/app/Models/stock.model.ts | 6 - frontend/src/app/Services/data.service.ts | 32 +++-- .../src/app/Services/token.service.spec.ts | 8 +- .../Views/dashboard/dashboard.component.html | 121 ++++++++---------- .../Views/dashboard/dashboard.component.ts | 63 +++++---- .../user-dialog/user-dialog.component.html | 1 + .../user-dialog/user-dialog.component.ts | 6 +- 8 files changed, 123 insertions(+), 120 deletions(-) diff --git a/frontend/src/app/Helpers/helper.service.ts b/frontend/src/app/Helpers/helper.service.ts index ac7ca1c..cfb0d3d 100644 --- a/frontend/src/app/Helpers/helper.service.ts +++ b/frontend/src/app/Helpers/helper.service.ts @@ -1,10 +1,8 @@ import { Injectable } from '@angular/core'; -import { Stock } from '../Models/stock.model'; @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class HelperService { - - constructor() { } + constructor() {} } diff --git a/frontend/src/app/Models/stock.model.ts b/frontend/src/app/Models/stock.model.ts index 4220de6..e69de29 100644 --- a/frontend/src/app/Models/stock.model.ts +++ b/frontend/src/app/Models/stock.model.ts @@ -1,6 +0,0 @@ -export class Stock { - count = 0; - price = 0; - symbol = ''; - time = ''; -} diff --git a/frontend/src/app/Services/data.service.ts b/frontend/src/app/Services/data.service.ts index 423756b..0a5eb26 100644 --- a/frontend/src/app/Services/data.service.ts +++ b/frontend/src/app/Services/data.service.ts @@ -88,21 +88,27 @@ export class DataService { public createTransaction( symbol: string, time: string, - count: BigInt, + count: number, price: number ): Observable { - time = time + 'T12:00:00.000'; - return this.http.post(API_URL + 'transactions', { - headers: new HttpHeaders({ - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + this.tokenStorage.getToken(), - }), - responseType: 'text', - count, - price, - symbol, - time, - }); + time = time + 'T12:00:00.000Z'; + price.toFixed(2); + console.log(this.tokenStorage.getToken()); + return this.http.post( + API_URL + 'transaction', + { + count, + price, + symbol, + time, + }, + { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + this.tokenStorage.getToken(), + }), + } + ); } /** diff --git a/frontend/src/app/Services/token.service.spec.ts b/frontend/src/app/Services/token.service.spec.ts index 7930902..bff5e17 100644 --- a/frontend/src/app/Services/token.service.spec.ts +++ b/frontend/src/app/Services/token.service.spec.ts @@ -1,13 +1,13 @@ import { TestBed } from '@angular/core/testing'; -import { TokenService } from './token.service'; +import { TokenStorageService } from './token.service'; -describe('TokenService', () => { - let service: TokenService; +describe('TokenStorageService', () => { + let service: TokenStorageService; beforeEach(() => { TestBed.configureTestingModule({}); - service = TestBed.inject(TokenService); + service = TestBed.inject(TokenStorageService); }); it('should be created', () => { diff --git a/frontend/src/app/Views/dashboard/dashboard.component.html b/frontend/src/app/Views/dashboard/dashboard.component.html index 3b2f32b..7f0b5e9 100644 --- a/frontend/src/app/Views/dashboard/dashboard.component.html +++ b/frontend/src/app/Views/dashboard/dashboard.component.html @@ -4,49 +4,39 @@
Aktienübersicht
- -
-
- - + +
+
+ - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - - - - -
Symbol{{ element.position }}Symbol{{ element.symbol }}Name{{ element.name }}Count{{ element.count }}Volume{{ element.weight }}Time{{ element.time }}Worth{{ element.symbol }}
-
+ + + +
+ @@ -74,39 +64,40 @@ add -
- - - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - -
Count{{ element.position }}Count{{ element.count }}Pirce{{ element.name }}Price{{ element.price }}Symbol{{ element.weight }}Symbol{{ element.symbol }}Time{{ element.symbol }}Time{{ element.time }}
-
+ + + diff --git a/frontend/src/app/Views/dashboard/dashboard.component.ts b/frontend/src/app/Views/dashboard/dashboard.component.ts index 3cb280b..c1dc35e 100644 --- a/frontend/src/app/Views/dashboard/dashboard.component.ts +++ b/frontend/src/app/Views/dashboard/dashboard.component.ts @@ -11,11 +11,10 @@ export interface PeriodicElement { } export interface Stock { + count: number; + // price: number; symbol: string; - count: Float32Array; - lastTransaction: Date; - boughtPrice: Float32Array; - currentPrice: Float32Array; + time: string; } //symbol count lastTransaction boughtPrice currentPrice(+?) @@ -24,29 +23,15 @@ const ELEMENT_DATA: PeriodicElement[] = [ { position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H' }, { position: 2, name: 'Helium', weight: 4.0026, symbol: 'He' }, { position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li' }, - { position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be' }, - { position: 5, name: 'Boron', weight: 10.811, symbol: 'B' }, - { position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C' }, - { position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N' }, - { position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O' }, - { position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F' }, - { position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne' }, - { position: 11, name: 'Hydrogen', weight: 1.0079, symbol: 'H' }, - { position: 12, name: 'Helium', weight: 4.0026, symbol: 'He' }, - { position: 13, name: 'Lithium', weight: 6.941, symbol: 'Li' }, - { position: 14, name: 'Beryllium', weight: 9.0122, symbol: 'Be' }, - { position: 15, name: 'Boron', weight: 10.811, symbol: 'B' }, - { position: 16, name: 'Carbon', weight: 12.0107, symbol: 'C' }, - { position: 17, name: 'Nitrogen', weight: 14.0067, symbol: 'N' }, - { position: 18, name: 'Oxygen', weight: 15.9994, symbol: 'O' }, - { position: 19, name: 'Fluorine', weight: 18.9984, symbol: 'F' }, - { position: 20, name: 'Neon', weight: 20.1797, symbol: 'Ne' }, ]; +var TRANSACTION_DATA: TransactionData[] = []; +var STOCK_DATA: Stock[] = []; + export interface TransactionData { symbol: string; time: string; - count: BigInt; + count: number; price: number; } @@ -58,14 +43,41 @@ export interface TransactionData { export class DashboardComponent implements OnInit { constructor(private dataService: DataService, public dialog: MatDialog) {} + dataSourceTransactions: TransactionData[] = []; + dataSourceStocks: Stock[] = []; + ngOnInit() { this.dataService.getStockData().subscribe((response: any) => { - console.log(response); + console.log('PORTFOLIO:' + response); + var data = JSON.parse(response); + for (let i = 0; i < data.data.length; i++) { + STOCK_DATA.push({ + count: data.data[i].count, + // price: data.data[i].price, + symbol: data.data[i].symbol, + time: data.data[i].last_transaction, + }); + } + console.log(STOCK_DATA); + this.dataSourceStocks = STOCK_DATA; //TODO map data on array for display + //TODO move to helper service }); this.dataService.getTransactionData().subscribe((response: any) => { - console.log(response); + console.log('TRANSACTIONS:' + response); + var data = JSON.parse(response); + for (let i = 0; i < data.data.length; i++) { + TRANSACTION_DATA.push({ + symbol: data.data[i].symbol, + time: data.data[i].time, + count: data.data[i].count, + price: data.data[i].price, + }); + } + console.log(TRANSACTION_DATA); + this.dataSourceTransactions = TRANSACTION_DATA; //TODO map data on array for display + //TODO move to helper service }); } @@ -91,6 +103,7 @@ export class DashboardComponent implements OnInit { }); } - displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; + displayedColumns: string[] = ['weight', 'position', 'name', 'symbol']; + displayedColumnsStocks: string[] = ['position', 'name', 'weight']; dataSource = ELEMENT_DATA; } diff --git a/frontend/src/app/Views/dashboard/user-dialog/user-dialog.component.html b/frontend/src/app/Views/dashboard/user-dialog/user-dialog.component.html index 67e6e52..21b87cf 100644 --- a/frontend/src/app/Views/dashboard/user-dialog/user-dialog.component.html +++ b/frontend/src/app/Views/dashboard/user-dialog/user-dialog.component.html @@ -50,6 +50,7 @@ [(ngModel)]="data.price" required #price="ngModel" + type="number" />