SES-13 implemented getCharacterStats method
This commit is contained in:
parent
ad951c9cf8
commit
145491fd2a
@ -1,14 +1,28 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { AbilityViewModel } from "../../../types/viewmodels/ability-viewmodels/AbilityViewModel";
|
import { AbilityViewModel } from "../../../types/viewmodels/ability-viewmodels/AbilityViewModel";
|
||||||
|
import {AppState} from "../../store/models/app-state.model";
|
||||||
|
import {Store} from "@ngrx/store";
|
||||||
|
import {first} from "rxjs/operators";
|
||||||
|
import {CharacterService} from "../../../services/character.service";
|
||||||
|
import {CharacterStatsViewModel} from "../../../types/viewmodels/character-viewmodels/CharacterStatsViewModel";
|
||||||
|
import {ErrorResponse} from "../../../types/ErrorResponse";
|
||||||
|
import {HttpErrorResponse} from "@angular/common/http";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-player-dashboard',
|
selector: 'app-player-dashboard',
|
||||||
templateUrl: './player-dashboard.component.html',
|
templateUrl: './player-dashboard.component.html',
|
||||||
styleUrls: ['./player-dashboard.component.css'],
|
styleUrls: ['./player-dashboard.component.css'],
|
||||||
})
|
})
|
||||||
export class PlayerDashboardComponent {
|
export class PlayerDashboardComponent implements OnInit {
|
||||||
isExpanded = false;
|
isExpanded = false;
|
||||||
selected = false;
|
selected = false;
|
||||||
|
characterStats: CharacterStatsViewModel[];
|
||||||
|
|
||||||
|
constructor(private store: Store<AppState>, private characterService: CharacterService) {}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.getCharacterStats();
|
||||||
|
}
|
||||||
|
|
||||||
ability: AbilityViewModel = {
|
ability: AbilityViewModel = {
|
||||||
id: 1,
|
id: 1,
|
||||||
@ -26,11 +40,21 @@ export class PlayerDashboardComponent {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
collapse() {
|
getCharacterStats() {
|
||||||
this.isExpanded = false;
|
this.store.select( s => s.playerStore.characterId).pipe(first()).subscribe((characterId) => {
|
||||||
|
this.characterService.getCharacterStats(characterId).pipe(first()).subscribe((characterStats) => {
|
||||||
|
this.characterStats = characterStats;
|
||||||
|
}, (error: ErrorResponse | HttpErrorResponse) => {
|
||||||
|
if (error instanceof HttpErrorResponse) {
|
||||||
|
error = error.error as ErrorResponse;
|
||||||
|
}
|
||||||
|
console.error(error.message);
|
||||||
|
});
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
this.isExpanded = !this.isExpanded;
|
this.isExpanded = !this.isExpanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import {Either} from '../types/Either';
|
|||||||
import {CharacterForLoginViewModel} from '../types/viewmodels/character-viewmodels/CharacterForLoginViewModel';
|
import {CharacterForLoginViewModel} from '../types/viewmodels/character-viewmodels/CharacterForLoginViewModel';
|
||||||
import {switchMap, retry} from 'rxjs/operators';
|
import {switchMap, retry} from 'rxjs/operators';
|
||||||
import {LoggedCharactersViewModel} from '../types/viewmodels/character-viewmodels/LoggedCharactersViewModel';
|
import {LoggedCharactersViewModel} from '../types/viewmodels/character-viewmodels/LoggedCharactersViewModel';
|
||||||
|
import {CharacterStatsViewModel} from "../types/viewmodels/character-viewmodels/CharacterStatsViewModel";
|
||||||
|
|
||||||
Injectable({
|
Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@ -41,4 +42,18 @@ export class CharacterService {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCharacterStats(characterId: number): Observable<CharacterStatsViewModel[]> {
|
||||||
|
const params = new HttpParams().set('characterId', characterId.toString())
|
||||||
|
return this.http.get<Either<CharacterStatsViewModel[], ErrorResponse>>( this.baseUrl + 'characterStats', {params}).pipe(
|
||||||
|
switchMap( response => {
|
||||||
|
if (response.isLeft) {
|
||||||
|
return of(response.left);
|
||||||
|
} else {
|
||||||
|
return throwError(response.right);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
export interface CharacterStatsViewModel {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
value: number;
|
||||||
|
modification: number;
|
||||||
|
savingThrows: number;
|
||||||
|
canSaveThrows: boolean;
|
||||||
|
skills: {
|
||||||
|
name: string;
|
||||||
|
value: number;
|
||||||
|
can: boolean;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user