diff --git a/frontend/src/app/Services/auth.service.ts b/frontend/src/app/Services/auth.service.ts index ad8a3ee..5420e5f 100644 --- a/frontend/src/app/Services/auth.service.ts +++ b/frontend/src/app/Services/auth.service.ts @@ -12,14 +12,14 @@ const httpOptions = { export class AuthService { constructor(private http: HttpClient) {} login(username: string, password: string): Observable { - return this.http.post(AUTH_API + 'login', { + return this.http.post(AUTH_API + '/login', { username, password, }); } register(username: string, password: string): Observable { return this.http.post( - AUTH_API + 'signup', + AUTH_API + '/register', { username, password, diff --git a/frontend/src/app/Services/data.service.ts b/frontend/src/app/Services/data.service.ts index ce44a05..4419d9f 100644 --- a/frontend/src/app/Services/data.service.ts +++ b/frontend/src/app/Services/data.service.ts @@ -1,22 +1,38 @@ import { Injectable } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; -const API_URL = 'http://localhost:8080/api/test/'; +import { TokenStorageService } from './token.service'; +const API_URL = 'https://aktienbot.flokaiser.com/api/'; @Injectable({ providedIn: 'root', }) export class DataService { - constructor(private http: HttpClient) {} - // getPublicContent(): Observable { - // return this.http.get(API_URL + 'all', { responseType: 'text' }); - // } - // getUserBoard(): Observable { - // return this.http.get(API_URL + 'user', { responseType: 'text' }); - // } - // getModeratorBoard(): Observable { - // return this.http.get(API_URL + 'mod', { responseType: 'text' }); - // } - // getAdminBoard(): Observable { - // return this.http.get(API_URL + 'admin', { responseType: 'text' }); - // } + constructor( + private http: HttpClient, + 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; + }); + } + + getKeywords(): Observable { + return this.http.get(API_URL + 'keywords', { + headers: this.headers, + responseType: 'text', + }); + } } diff --git a/frontend/src/app/Views/bot-settings/bot-settings.component.html b/frontend/src/app/Views/bot-settings/bot-settings.component.html new file mode 100644 index 0000000..58d7a42 --- /dev/null +++ b/frontend/src/app/Views/bot-settings/bot-settings.component.html @@ -0,0 +1 @@ +

bot-settings works!

diff --git a/frontend/src/app/Views/bot-settings/bot-settings.component.scss b/frontend/src/app/Views/bot-settings/bot-settings.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/Views/bot-settings/bot-settings.component.spec.ts b/frontend/src/app/Views/bot-settings/bot-settings.component.spec.ts new file mode 100644 index 0000000..7fb7c50 --- /dev/null +++ b/frontend/src/app/Views/bot-settings/bot-settings.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { BotSettingsComponent } from './bot-settings.component'; + +describe('BotSettingsComponent', () => { + let component: BotSettingsComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ BotSettingsComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(BotSettingsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/Views/bot-settings/bot-settings.component.ts b/frontend/src/app/Views/bot-settings/bot-settings.component.ts new file mode 100644 index 0000000..40bd01b --- /dev/null +++ b/frontend/src/app/Views/bot-settings/bot-settings.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-bot-settings', + templateUrl: './bot-settings.component.html', + styleUrls: ['./bot-settings.component.scss'] +}) +export class BotSettingsComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/frontend/src/app/Views/dashboard/dashboard.component.html b/frontend/src/app/Views/dashboard/dashboard.component.html index 48693ac..6e0692a 100644 --- a/frontend/src/app/Views/dashboard/dashboard.component.html +++ b/frontend/src/app/Views/dashboard/dashboard.component.html @@ -9,6 +9,7 @@ mat-icon-button class="add-icon" aria-label="Example icon-button with heart icon" + [disableRipple]="true" > add diff --git a/frontend/src/app/Views/dashboard/dashboard.component.scss b/frontend/src/app/Views/dashboard/dashboard.component.scss index 6e05092..7bc1360 100644 --- a/frontend/src/app/Views/dashboard/dashboard.component.scss +++ b/frontend/src/app/Views/dashboard/dashboard.component.scss @@ -47,7 +47,8 @@ .add-icon { transform: scale(2); - padding-top: 1%; + margin-top: 2%; + outline: none !important; } .right-side { diff --git a/frontend/src/app/Views/dashboard/dashboard.component.ts b/frontend/src/app/Views/dashboard/dashboard.component.ts index 5752606..ff2d717 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,13 @@ const ELEMENT_DATA: PeriodicElement[] = [ styleUrls: ['./dashboard.component.scss'], }) export class DashboardComponent implements OnInit { - constructor() {} + constructor(private dataService: DataService) {} - ngOnInit(): void {} + //TODO avoid using ngOnInit() like this + //TODO fix server problems + async ngOnInit() { + const data = await this.dataService.getStockData(); + } displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; dataSource = ELEMENT_DATA; diff --git a/frontend/src/app/Views/header/header.component.html b/frontend/src/app/Views/header/header.component.html index 531c85e..d72ba56 100644 --- a/frontend/src/app/Views/header/header.component.html +++ b/frontend/src/app/Views/header/header.component.html @@ -5,7 +5,22 @@ mat-icon-button class="example-icon favorite-icon" aria-label="Example icon-button with heart icon" + [matMenuTriggerFor]="menu" > settings + + + + + diff --git a/frontend/src/app/Views/header/header.component.ts b/frontend/src/app/Views/header/header.component.ts index 7ab4cf7..07e63ab 100644 --- a/frontend/src/app/Views/header/header.component.ts +++ b/frontend/src/app/Views/header/header.component.ts @@ -1,15 +1,22 @@ import { Component, OnInit } from '@angular/core'; +import { TokenStorageService } from 'src/app/Services/token.service'; @Component({ selector: 'app-header', templateUrl: './header.component.html', - styleUrls: ['./header.component.scss'] + styleUrls: ['./header.component.scss'], }) export class HeaderComponent implements OnInit { + /** + * @param {TokenStorageService} privatetokenStorage + */ + constructor(private tokenStorage: TokenStorageService) {} - constructor() { } + ngOnInit(): void {} - ngOnInit(): void { + //logout() clears session storage; All user data is eradicated from it and page is reloaded + logout() { + this.tokenStorage.signOut(); + location.reload(); } - } diff --git a/frontend/src/app/Views/login/login.component.ts b/frontend/src/app/Views/login/login.component.ts index 9b5bfb5..dac1bc2 100644 --- a/frontend/src/app/Views/login/login.component.ts +++ b/frontend/src/app/Views/login/login.component.ts @@ -18,29 +18,36 @@ export class LoginComponent implements OnInit { errorMessage = ''; accountName = ''; + /** + * @param {AuthService} privateauthService + * @param {TokenStorageService} privatetokenStorage + * @param {Router} privaterouter + */ constructor( private authService: AuthService, private tokenStorage: TokenStorageService, private router: Router ) {} + + //ngOnInit() checks if a ngOnInit(): void { this.tokenStorage.signOut(); if (this.tokenStorage.getToken()) { this.isLoggedIn = true; } } + + //onSubmit() saves valuable information in session storage onSubmit(): void { const { username, password } = this.form; - console.log(username, password); this.authService.login(username, password).subscribe( (data) => { - this.tokenStorage.saveToken(data.accessToken); - this.tokenStorage.saveUser(data); + this.tokenStorage.saveToken(data.data.token); + this.tokenStorage.saveUser(data.data); this.isLoginFailed = false; this.isLoggedIn = true; this.accountName = username; - console.log(this.isLoggedIn); this.router.navigate(['']); }, (err) => { @@ -49,6 +56,8 @@ export class LoginComponent implements OnInit { } ); } + + //reloadPage() reloads the page reloadPage(): void { window.location.reload(); } diff --git a/frontend/src/app/Views/profile/profile.component.html b/frontend/src/app/Views/profile/profile.component.html new file mode 100644 index 0000000..9df0576 --- /dev/null +++ b/frontend/src/app/Views/profile/profile.component.html @@ -0,0 +1 @@ +

profile works!

diff --git a/frontend/src/app/Views/profile/profile.component.scss b/frontend/src/app/Views/profile/profile.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/Views/profile/profile.component.spec.ts b/frontend/src/app/Views/profile/profile.component.spec.ts new file mode 100644 index 0000000..e88012e --- /dev/null +++ b/frontend/src/app/Views/profile/profile.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ProfileComponent } from './profile.component'; + +describe('ProfileComponent', () => { + let component: ProfileComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ ProfileComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(ProfileComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/Views/profile/profile.component.ts b/frontend/src/app/Views/profile/profile.component.ts new file mode 100644 index 0000000..89b667f --- /dev/null +++ b/frontend/src/app/Views/profile/profile.component.ts @@ -0,0 +1,12 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-profile', + templateUrl: './profile.component.html', + styleUrls: ['./profile.component.scss'], +}) +export class ProfileComponent implements OnInit { + constructor() {} + + ngOnInit(): void {} +} diff --git a/frontend/src/app/Views/register/register.component.html b/frontend/src/app/Views/register/register.component.html index 2e2c38c..486f037 100644 --- a/frontend/src/app/Views/register/register.component.html +++ b/frontend/src/app/Views/register/register.component.html @@ -53,6 +53,23 @@ +
+ + +
+
+ Confirmation is required +
+
+
diff --git a/frontend/src/app/Views/register/register.component.ts b/frontend/src/app/Views/register/register.component.ts index 728792b..c032d71 100644 --- a/frontend/src/app/Views/register/register.component.ts +++ b/frontend/src/app/Views/register/register.component.ts @@ -15,13 +15,17 @@ export class RegisterComponent implements OnInit { isSuccessful = false; isSignUpFailed = false; errorMessage = ''; + + /** + * @param {AuthService} privateauthService + * @param {Router} privaterouter + */ constructor(private authService: AuthService, private router: Router) {} ngOnInit(): void {} onSubmit(): void { const { username, password } = this.form; this.authService.register(username, password).subscribe( (data) => { - console.log(data); this.isSuccessful = true; this.isSignUpFailed = false; this.router.navigate(['/login']); diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index b1926d3..6d05a46 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -2,6 +2,7 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { DashboardComponent } from './Views/dashboard/dashboard.component'; import { LoginComponent } from './Views/login/login.component'; +import { ProfileComponent } from './Views/profile/profile.component'; import { RegisterComponent } from './Views/register/register.component'; const routes: Routes = [ @@ -17,6 +18,14 @@ const routes: Routes = [ path: 'register', component: RegisterComponent, }, + { + path: 'profile', + component: ProfileComponent, + }, + { + path: 'settings', + component: ProfileComponent, + }, ]; @NgModule({ diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index e3465f6..1a1d467 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -13,8 +13,8 @@ export class AppComponent { * Application title. */ title = 'Aktienbot'; - showHeader = false; + showHeader = false; isLoggedIn = false; /** @@ -26,6 +26,7 @@ export class AppComponent { private router: Router, private tokenStorage: TokenStorageService ) { + //check if it is login or registration page, header should not show there this.router.events .pipe(filter((event) => event instanceof NavigationEnd)) .subscribe((event) => { @@ -33,11 +34,15 @@ export class AppComponent { (event as NavigationEnd).url === '/login' || (event as NavigationEnd).url === '/register' ); + + //check if token already exists from past login if (this.tokenStorage.getToken()) { this.isLoggedIn = true; } else { this.isLoggedIn = false; } + + //prevent user from accessing dashboard if not logged in if ( this.isLoggedIn === false && (event as NavigationEnd).url != '/register' diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index ebc1537..1e925aa 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -9,6 +9,7 @@ import { MatButtonModule } from '@angular/material/button'; import { MatGridListModule } from '@angular/material/grid-list'; import { MatCardModule } from '@angular/material/card'; import { MatTableModule } from '@angular/material/table'; +import { MatMenuModule } from '@angular/material/menu'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @@ -17,6 +18,8 @@ import { HeaderComponent } from './Views/header/header.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { DashboardComponent } from './Views/dashboard/dashboard.component'; import { RegisterComponent } from './Views/register/register.component'; +import { ProfileComponent } from './Views/profile/profile.component'; +import { BotSettingsComponent } from './Views/bot-settings/bot-settings.component'; @NgModule({ declarations: [ @@ -25,6 +28,8 @@ import { RegisterComponent } from './Views/register/register.component'; HeaderComponent, DashboardComponent, RegisterComponent, + ProfileComponent, + BotSettingsComponent, ], imports: [ BrowserModule, @@ -38,6 +43,7 @@ import { RegisterComponent } from './Views/register/register.component'; MatTableModule, FormsModule, HttpClientModule, + MatMenuModule, ], providers: [], bootstrap: [AppComponent],