From b9928d6ce002c661e6cb4224098085af26e477ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20G=C3=B3reczny?= Date: Sun, 13 Dec 2020 11:19:01 +0100 Subject: [PATCH 1/3] SES-89 Added api connection service and display error --- .../ClientApp/src/app.routing.ts | 6 +++++ .../ClientApp/src/app/app.module.ts | 7 ++++- .../components/sign-in/sign-in.component.html | 11 +++++--- .../components/sign-in/sign-in.component.ts | 17 +++++++++--- .../ClientApp/src/services/user.service.ts | 22 +++++++++++++++ .../ClientApp/src/types/Either.ts | 5 ++++ .../ClientApp/src/types/ErrorResponse.ts | 4 +++ .../Controllers/UserController.cs | 27 ++++++++++++++++--- .../SessionCompanion/SessionCompanion.xml | 8 ++++++ 9 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 SessionCompanion/SessionCompanion/ClientApp/src/services/user.service.ts create mode 100644 SessionCompanion/SessionCompanion/ClientApp/src/types/Either.ts create mode 100644 SessionCompanion/SessionCompanion/ClientApp/src/types/ErrorResponse.ts diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app.routing.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app.routing.ts index 344501c..a2f9ceb 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app.routing.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app.routing.ts @@ -3,6 +3,7 @@ import { SelectRoleComponent } from './app/components/select-role/select-role.co import { SignInComponent } from './app/components/sign-in/sign-in.component'; import { RegistrationComponent } from './app/components/registration/registration.component'; import {GameMasterDashboardComponent} from './app/components/game-master-dashboard/game-master-dashboard.component'; +import {PlayerDashboardComponent} from './app/components/player-dashboard/player-dashboard.component'; const routes: Routes = [ { @@ -24,6 +25,11 @@ const routes: Routes = [ path: 'gamemaster', component: GameMasterDashboardComponent, pathMatch: 'full' + }, + { + path: 'player', + component: PlayerDashboardComponent, + pathMatch: 'full' } ]; diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts index 5587ba6..c0eccab 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts @@ -9,6 +9,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { SignInComponent } from './components/sign-in/sign-in.component'; import { RegistrationComponent } from './components/registration/registration.component'; import { GameMasterDashboardComponent} from './components/game-master-dashboard/game-master-dashboard.component'; +import {PlayerDashboardComponent} from './components/player-dashboard/player-dashboard.component'; import { MatCardModule, MatTabsModule, @@ -18,6 +19,7 @@ import { MatCheckboxModule, MatIconModule, MatSidenavModule, MatToolbarModule, MatListModule } from '@angular/material'; +import {UserService} from '../services/user.service'; @NgModule({ declarations: [ @@ -26,6 +28,7 @@ import { SignInComponent, RegistrationComponent, GameMasterDashboardComponent, + PlayerDashboardComponent ], imports: [ BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }), @@ -45,7 +48,9 @@ BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }), MatToolbarModule, MatListModule, ], - providers: [], + providers: [ + UserService + ], bootstrap: [AppComponent] }) export class AppModule { } diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/sign-in/sign-in.component.html b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/sign-in/sign-in.component.html index efeb015..d9feec4 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/sign-in/sign-in.component.html +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/sign-in/sign-in.component.html @@ -6,7 +6,7 @@ - + + {{apiErrorMessage}} + - \ No newline at end of file + diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/sign-in/sign-in.component.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/sign-in/sign-in.component.ts index 61488ad..aba66e0 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/sign-in/sign-in.component.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/sign-in/sign-in.component.ts @@ -1,14 +1,18 @@ -import { Component } from '@angular/core'; +import { Component, OnDestroy } from '@angular/core'; import { FormGroup, Validators, FormBuilder } from '@angular/forms'; import { Router } from '@angular/router'; import {UserService} from '../../../services/user.service'; +import {ErrorResponse} from '../../../types/ErrorResponse'; +import {Subscription} from 'rxjs'; @Component({ selector: 'app-sign-in', templateUrl: './sign-in.component.html', styleUrls: ['./sign-in.component.css'] }) -export class SignInComponent { +export class SignInComponent implements OnDestroy { + allSubscriptions = new Subscription(); + isExpanded = false; apiError = false; apiErrorMessage = ''; @@ -24,16 +28,19 @@ export class SignInComponent { }) }); - async onLoginButtonClick() { - const result = await this.userService.tryLogin( + onLoginButtonClick() { + this.allSubscriptions.add( + this.userService.tryLogin( this.signInFormGroup.get('signIn').value['username'], - this.signInFormGroup.get('signIn').value['password']); - if (result.isLeft) { - await this.router.navigate(['player']); - } else { - this.apiError = true; - this.apiErrorMessage = result.right.message; - } + this.signInFormGroup.get('signIn').value['password']).subscribe( + (success) => { + this.router.navigate(['player']); + }, + (error: ErrorResponse) => { + this.apiError = true; + this.apiErrorMessage = error.message; + } + )); } onRegisterButtonClick(){ @@ -52,4 +59,8 @@ export class SignInComponent { toggle() { this.isExpanded = !this.isExpanded; } + + ngOnDestroy() { + this.allSubscriptions.unsubscribe(); + } } diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/services/user.service.ts b/SessionCompanion/SessionCompanion/ClientApp/src/services/user.service.ts index 08718fe..fda8c51 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/services/user.service.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/services/user.service.ts @@ -1,8 +1,9 @@ import {Inject, Injectable} from '@angular/core'; import {HttpClient, HttpParams} from '@angular/common/http'; -import {Observable} from 'rxjs'; +import {Observable, of, throwError} from 'rxjs'; import {ErrorResponse} from '../types/ErrorResponse'; import {Either} from '../types/Either'; +import {switchMap} from 'rxjs/operators'; Injectable({ providedIn: 'root' @@ -13,10 +14,18 @@ export class UserService { this.baseUrl = baseUrl + this.baseUrl; } - async tryLogin(login: string, password: string): Promise> { + tryLogin(login: string, password: string): Observable { const params = new HttpParams() .set('userName', login) .set('password', password); - return await this.http.get>(this.baseUrl + 'login', { params }).toPromise(); + return this.http.get>(this.baseUrl + 'login', { params }).pipe( + switchMap(response => { + if (response.isLeft) { + return of(response.left); + } else { + return throwError(response.right); + } + }) + ); } } From 57759fb91e0f7239a878afe28cf1875496547864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20G=C3=B3reczny?= Date: Sun, 13 Dec 2020 13:27:45 +0100 Subject: [PATCH 3/3] SES-89 type change --- .../app/components/registration/registration.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/registration/registration.component.html b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/registration/registration.component.html index 54f6124..4c1caa0 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/registration/registration.component.html +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/registration/registration.component.html @@ -23,7 +23,7 @@ formControlName="password" required placeholder="Password" - [type]="true ? 'password' : 'text'" + type="password" name="password"/> lock @@ -37,7 +37,7 @@ formControlName="confirmPassword" required placeholder="Confirm Password" - [type]="true ? 'password' : 'text'" + type="password" name="confirmPassword"/> lock