Improve Http Request
This commit is contained in:
parent
0393f153bf
commit
e9f1e7d38a
@ -7,7 +7,7 @@ import {
|
|||||||
} from '@angular/common/http';
|
} from '@angular/common/http';
|
||||||
import { TokenStorageService } from '../Services/token.service';
|
import { TokenStorageService } from '../Services/token.service';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
const TOKEN_HEADER_KEY = 'Authorization'; // for Spring Boot back-end
|
const TOKEN_HEADER_KEY = 'Authorization';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthInterceptor implements HttpInterceptor {
|
export class AuthInterceptor implements HttpInterceptor {
|
||||||
constructor(private token: TokenStorageService) {}
|
constructor(private token: TokenStorageService) {}
|
||||||
|
16
frontend/src/app/Helpers/helper.service.spec.ts
Normal file
16
frontend/src/app/Helpers/helper.service.spec.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { HelperService } from './helper.service';
|
||||||
|
|
||||||
|
describe('HelperService', () => {
|
||||||
|
let service: HelperService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(HelperService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
10
frontend/src/app/Helpers/helper.service.ts
Normal file
10
frontend/src/app/Helpers/helper.service.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Stock } from '../Models/stock.model';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class HelperService {
|
||||||
|
|
||||||
|
constructor() { }
|
||||||
|
}
|
6
frontend/src/app/Models/stock.model.ts
Normal file
6
frontend/src/app/Models/stock.model.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export class Stock {
|
||||||
|
count = 0;
|
||||||
|
price = 0;
|
||||||
|
symbol = '';
|
||||||
|
time = '';
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable, OnInit } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { delay, Observable } from 'rxjs';
|
||||||
import { TokenStorageService } from './token.service';
|
import { TokenStorageService } from './token.service';
|
||||||
const API_URL = 'https://aktienbot.flokaiser.com/api/';
|
const API_URL = 'https://aktienbot.flokaiser.com/api/';
|
||||||
@Injectable({
|
@Injectable({
|
||||||
@ -12,26 +12,32 @@ export class DataService {
|
|||||||
private tokenStorage: TokenStorageService
|
private tokenStorage: TokenStorageService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
headers = new HttpHeaders({
|
public getStockData(): Observable<any> {
|
||||||
'Content-Type': 'application/json',
|
return this.http.get(API_URL + 'portfolio', {
|
||||||
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
headers: new HttpHeaders({
|
||||||
});
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
||||||
async getStockData() {
|
}),
|
||||||
await this.http
|
responseType: 'text',
|
||||||
.get(API_URL + 'portfolio', {
|
});
|
||||||
headers: this.headers,
|
|
||||||
responseType: 'text',
|
|
||||||
})
|
|
||||||
.subscribe((data) => {
|
|
||||||
console.log(data);
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getKeywords(): Observable<any> {
|
public getTransactionData(): Observable<any> {
|
||||||
|
return this.http.get(API_URL + 'transactions', {
|
||||||
|
headers: new HttpHeaders({
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
||||||
|
}),
|
||||||
|
responseType: 'text',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public getKeywords(): Observable<any> {
|
||||||
return this.http.get(API_URL + 'keywords', {
|
return this.http.get(API_URL + 'keywords', {
|
||||||
headers: this.headers,
|
headers: new HttpHeaders({
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: 'Bearer ' + this.tokenStorage.getToken(),
|
||||||
|
}),
|
||||||
responseType: 'text',
|
responseType: 'text',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,39 @@
|
|||||||
<div class="heading fix-right-side">
|
<div class="heading fix-right-side">
|
||||||
<div class="vertical-center">Transaktionen</div>
|
<div class="vertical-center">Transaktionen</div>
|
||||||
</div>
|
</div>
|
||||||
<mat-card class="placeholder"></mat-card>
|
<div class="stockTable">
|
||||||
|
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
|
||||||
|
<!--- Note that these columns can be defined in any order.
|
||||||
|
The actual rendered columns are set as a property on the row definition" -->
|
||||||
|
|
||||||
|
<!-- Position Column -->
|
||||||
|
<ng-container matColumnDef="position">
|
||||||
|
<th mat-header-cell *matHeaderCellDef>Count</th>
|
||||||
|
<td mat-cell *matCellDef="let element">{{ element.position }}</td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<!-- Name Column -->
|
||||||
|
<ng-container matColumnDef="name">
|
||||||
|
<th mat-header-cell *matHeaderCellDef>Pirce</th>
|
||||||
|
<td mat-cell *matCellDef="let element">{{ element.name }}</td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<!-- Weight Column -->
|
||||||
|
<ng-container matColumnDef="weight">
|
||||||
|
<th mat-header-cell *matHeaderCellDef>Symbol</th>
|
||||||
|
<td mat-cell *matCellDef="let element">{{ element.weight }}</td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<!-- Symbol Column -->
|
||||||
|
<ng-container matColumnDef="symbol">
|
||||||
|
<th mat-header-cell *matHeaderCellDef>Time</th>
|
||||||
|
<td mat-cell *matCellDef="let element">{{ element.symbol }}</td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||||
|
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</mat-grid-tile>
|
</mat-grid-tile>
|
||||||
</mat-grid-list>
|
</mat-grid-list>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { throwToolbarMixedModesError } from '@angular/material/toolbar';
|
import { throwToolbarMixedModesError } from '@angular/material/toolbar';
|
||||||
import { DataService } from 'src/app/Services/data.service';
|
import { DataService } from 'src/app/Services/data.service';
|
||||||
|
import { TokenStorageService } from 'src/app/Services/token.service';
|
||||||
|
|
||||||
export interface PeriodicElement {
|
export interface PeriodicElement {
|
||||||
name: string;
|
name: string;
|
||||||
@ -49,11 +50,15 @@ const ELEMENT_DATA: PeriodicElement[] = [
|
|||||||
})
|
})
|
||||||
export class DashboardComponent implements OnInit {
|
export class DashboardComponent implements OnInit {
|
||||||
constructor(private dataService: DataService) {}
|
constructor(private dataService: DataService) {}
|
||||||
|
ngOnInit() {
|
||||||
//TODO avoid using ngOnInit() like this
|
this.dataService.getStockData().subscribe((response: any) => {
|
||||||
//TODO fix server problems
|
console.log(response);
|
||||||
async ngOnInit() {
|
//TODO map data on array for display
|
||||||
const data = await this.dataService.getStockData();
|
});
|
||||||
|
this.dataService.getTransactionData().subscribe((response: any) => {
|
||||||
|
console.log(response);
|
||||||
|
//TODO map data on array for display
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
|
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
|
||||||
|
@ -29,7 +29,7 @@ export class LoginComponent implements OnInit {
|
|||||||
private router: Router
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
//ngOnInit() checks if a
|
//ngOnInit() checks if a user is logged in
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.tokenStorage.signOut();
|
this.tokenStorage.signOut();
|
||||||
if (this.tokenStorage.getToken()) {
|
if (this.tokenStorage.getToken()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user