diff --git a/frontend/src/app/Helpers/auth.interceptor.ts b/frontend/src/app/Helpers/auth.interceptor.ts index ff94e91..c013dd5 100644 --- a/frontend/src/app/Helpers/auth.interceptor.ts +++ b/frontend/src/app/Helpers/auth.interceptor.ts @@ -7,7 +7,7 @@ import { } from '@angular/common/http'; import { TokenStorageService } from '../Services/token.service'; import { Observable } from 'rxjs'; -const TOKEN_HEADER_KEY = 'Authorization'; // for Spring Boot back-end +const TOKEN_HEADER_KEY = 'Authorization'; @Injectable() export class AuthInterceptor implements HttpInterceptor { constructor(private token: TokenStorageService) {} diff --git a/frontend/src/app/Helpers/helper.service.spec.ts b/frontend/src/app/Helpers/helper.service.spec.ts new file mode 100644 index 0000000..00b56e5 --- /dev/null +++ b/frontend/src/app/Helpers/helper.service.spec.ts @@ -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(); + }); +}); diff --git a/frontend/src/app/Helpers/helper.service.ts b/frontend/src/app/Helpers/helper.service.ts new file mode 100644 index 0000000..ac7ca1c --- /dev/null +++ b/frontend/src/app/Helpers/helper.service.ts @@ -0,0 +1,10 @@ +import { Injectable } from '@angular/core'; +import { Stock } from '../Models/stock.model'; + +@Injectable({ + providedIn: 'root' +}) +export class HelperService { + + constructor() { } +} diff --git a/frontend/src/app/Models/stock.model.ts b/frontend/src/app/Models/stock.model.ts new file mode 100644 index 0000000..4220de6 --- /dev/null +++ b/frontend/src/app/Models/stock.model.ts @@ -0,0 +1,6 @@ +export class Stock { + count = 0; + price = 0; + symbol = ''; + time = ''; +} diff --git a/frontend/src/app/Services/auth.service.ts b/frontend/src/app/Services/auth.service.ts index 5420e5f..c5de4fb 100644 --- a/frontend/src/app/Services/auth.service.ts +++ b/frontend/src/app/Services/auth.service.ts @@ -11,18 +11,19 @@ const httpOptions = { }) export class AuthService { constructor(private http: HttpClient) {} - login(username: string, password: string): Observable { + login(email: string, password: string): Observable { return this.http.post(AUTH_API + '/login', { - username, + email, password, }); } - register(username: string, password: string): Observable { + register(email: string, username: string, password: string): Observable { return this.http.post( AUTH_API + '/register', { - username, + email, password, + username, }, httpOptions ); diff --git a/frontend/src/app/Services/data.service.ts b/frontend/src/app/Services/data.service.ts index 4419d9f..bbd1863 100644 --- a/frontend/src/app/Services/data.service.ts +++ b/frontend/src/app/Services/data.service.ts @@ -1,6 +1,6 @@ -import { Injectable } from '@angular/core'; +import { Injectable, OnInit } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; -import { Observable } from 'rxjs'; +import { delay, Observable } from 'rxjs'; import { TokenStorageService } from './token.service'; const API_URL = 'https://aktienbot.flokaiser.com/api/'; @Injectable({ @@ -12,26 +12,32 @@ export class DataService { private tokenStorage: TokenStorageService ) {} - headers = new HttpHeaders({ - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + this.tokenStorage.getToken(), - }); - - async getStockData() { - await this.http - .get(API_URL + 'portfolio', { - headers: this.headers, - responseType: 'text', - }) - .subscribe((data) => { - console.log(data); - return data; - }); + public getStockData(): Observable { + return this.http.get(API_URL + 'portfolio', { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + this.tokenStorage.getToken(), + }), + responseType: 'text', + }); } - getKeywords(): Observable { + public getTransactionData(): Observable { + return this.http.get(API_URL + 'transactions', { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + this.tokenStorage.getToken(), + }), + responseType: 'text', + }); + } + + public getKeywords(): Observable { return this.http.get(API_URL + 'keywords', { - headers: this.headers, + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + this.tokenStorage.getToken(), + }), responseType: 'text', }); } diff --git a/frontend/src/app/Views/dashboard/dashboard.component.html b/frontend/src/app/Views/dashboard/dashboard.component.html index 6e0692a..5c1b401 100644 --- a/frontend/src/app/Views/dashboard/dashboard.component.html +++ b/frontend/src/app/Views/dashboard/dashboard.component.html @@ -64,7 +64,39 @@
Transaktionen
- +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Count{{ element.position }}Pirce{{ element.name }}Symbol{{ element.weight }}Time{{ element.symbol }}
+
diff --git a/frontend/src/app/Views/dashboard/dashboard.component.ts b/frontend/src/app/Views/dashboard/dashboard.component.ts index ff2d717..27a6140 100644 --- a/frontend/src/app/Views/dashboard/dashboard.component.ts +++ b/frontend/src/app/Views/dashboard/dashboard.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { throwToolbarMixedModesError } from '@angular/material/toolbar'; import { DataService } from 'src/app/Services/data.service'; +import { TokenStorageService } from 'src/app/Services/token.service'; export interface PeriodicElement { name: string; @@ -49,11 +50,15 @@ const ELEMENT_DATA: PeriodicElement[] = [ }) export class DashboardComponent implements OnInit { constructor(private dataService: DataService) {} - - //TODO avoid using ngOnInit() like this - //TODO fix server problems - async ngOnInit() { - const data = await this.dataService.getStockData(); + ngOnInit() { + this.dataService.getStockData().subscribe((response: any) => { + console.log(response); + //TODO map data on array for display + }); + this.dataService.getTransactionData().subscribe((response: any) => { + console.log(response); + //TODO map data on array for display + }); } displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; diff --git a/frontend/src/app/Views/login/login.component.html b/frontend/src/app/Views/login/login.component.html index b1ce7dc..42f01b4 100644 --- a/frontend/src/app/Views/login/login.component.html +++ b/frontend/src/app/Views/login/login.component.html @@ -14,21 +14,21 @@ class="backgorund" >
- + -
diff --git a/frontend/src/app/Views/login/login.component.ts b/frontend/src/app/Views/login/login.component.ts index dac1bc2..a020f4a 100644 --- a/frontend/src/app/Views/login/login.component.ts +++ b/frontend/src/app/Views/login/login.component.ts @@ -10,7 +10,7 @@ import { Router } from '@angular/router'; }) export class LoginComponent implements OnInit { form: any = { - username: null, + email: null, password: null, }; isLoggedIn = false; @@ -29,7 +29,7 @@ export class LoginComponent implements OnInit { private router: Router ) {} - //ngOnInit() checks if a + //ngOnInit() checks if a user is logged in ngOnInit(): void { this.tokenStorage.signOut(); if (this.tokenStorage.getToken()) { @@ -39,15 +39,15 @@ export class LoginComponent implements OnInit { //onSubmit() saves valuable information in session storage onSubmit(): void { - const { username, password } = this.form; - this.authService.login(username, password).subscribe( + const { email, password } = this.form; + this.authService.login(email, password).subscribe( (data) => { this.tokenStorage.saveToken(data.data.token); this.tokenStorage.saveUser(data.data); this.isLoginFailed = false; this.isLoggedIn = true; - this.accountName = username; + this.accountName = email; this.router.navigate(['']); }, (err) => { diff --git a/frontend/src/app/Views/register/register.component.html b/frontend/src/app/Views/register/register.component.html index 486f037..6b21679 100644 --- a/frontend/src/app/Views/register/register.component.html +++ b/frontend/src/app/Views/register/register.component.html @@ -35,6 +35,24 @@
+
+ + +
+
Email is required
+
+ Email must be a valid email address +
+
+
{ this.isSuccessful = true; this.isSignUpFailed = false; diff --git a/frontend/src/index.html b/frontend/src/index.html index 4da32cc..371b2a9 100644 --- a/frontend/src/index.html +++ b/frontend/src/index.html @@ -5,7 +5,6 @@ Aktienbot -