Merge pull request 'SES-149 Added sevice and monster table' (#74) from SES-149 into dev

Reviewed-on: #74
This commit is contained in:
Natalia Gawron 2021-01-16 19:24:44 +01:00
commit a7ac3e65f2
18 changed files with 350 additions and 28 deletions

View File

@ -0,0 +1,14 @@
using SessionCompanion.Database.Tables;
using SessionCompanion.Services.Base;
namespace SessionCompanion.Services.Interfaces
{
using System.Collections.Generic;
using SessionCompanion.ViewModels.MonsterViewModels;
public interface IMonsterService : IServiceBase<MonsterViewModel, Monster>
{
List<MonsterViewModel> GetAllMonstersList();
}
}

View File

@ -0,0 +1,15 @@
using AutoMapper;
using SessionCompanion.Database.Tables;
namespace SessionCompanion.Services.Profiles
{
using SessionCompanion.ViewModels.MonsterViewModels;
public class MonsterProfile : Profile
{
public MonsterProfile()
{
CreateMap<MonsterViewModel, Monster>().ReverseMap();
}
}
}

View File

@ -0,0 +1,29 @@
using AutoMapper;
using SessionCompanion.Database.Repositories.Base;
using SessionCompanion.Database.Tables;
using SessionCompanion.Services.Base;
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.IntelligenceViewModels;
using System;
using System.Collections.Generic;
using System.Text;
namespace SessionCompanion.Services.Services
{
using System.Threading.Tasks;
using SessionCompanion.ViewModels.MonsterViewModels;
public class MonsterService : ServiceBase<MonsterViewModel, Monster>, IMonsterService
{
public MonsterService(IMapper mapper, IRepository<Monster> repository) : base(mapper, repository)
{ }
public List<MonsterViewModel> GetAllMonstersList()
{
var monsters = this.Repository.Get();
return this.Mapper.Map<List<MonsterViewModel>>(monsters);
}
}
}

View File

@ -44,6 +44,8 @@ import { SpellService } from '../services/spell.service';
import { WeaponService } from '../services/weapon.service';
import { ArmorService } from '../services/armor.service';
import { OtherEquipmentService } from '../services/other-equipment.service';
import { GameMasterMonstersTableComponent } from './components/game-master-monsters-table/game-master-monsters-table.component';
import { MonsterService } from '../services/monster.service';
@NgModule({
declarations: [
@ -60,6 +62,7 @@ import { OtherEquipmentService } from '../services/other-equipment.service';
GameMasterArmorsTableComponent,
GameMasterWeaponsTableComponent,
GameMasterCharacterActionsDialogComponent,
GameMasterMonstersTableComponent,
],
imports: [
BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
@ -95,12 +98,14 @@ import { OtherEquipmentService } from '../services/other-equipment.service';
WeaponService,
ArmorService,
OtherEquipmentService,
MonsterService,
],
bootstrap: [AppComponent],
entryComponents: [
GameMasterSpellsTableComponent,
GameMasterArmorsTableComponent,
GameMasterWeaponsTableComponent,
GameMasterMonstersTableComponent,
AbilitiesComponent,
GameMasterCharacterActionsDialogComponent,
],

View File

@ -6,27 +6,27 @@
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="Name">
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
<td mat-cell *matCellDef="let row"> {{row.name}} </td>
</ng-container>
<ng-container matColumnDef="Category">
<ng-container matColumnDef="category">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Category </th>
<td mat-cell *matCellDef="let row"> {{row.category}} </td>
</ng-container>
<ng-container matColumnDef="MinimumStrength">
<ng-container matColumnDef="minimumStrength">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Minimum Strength </th>
<td mat-cell *matCellDef="let row"> {{row.minimumStrength}}% </td>
</ng-container>
<ng-container matColumnDef="Weight">
<ng-container matColumnDef="weight">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Weight </th>
<td mat-cell *matCellDef="let row"> {{row.weight}} </td>
</ng-container>
<ng-container matColumnDef="Cost">
<ng-container matColumnDef="cost">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Cost </th>
<td mat-cell *matCellDef="let row"> {{row.cost}} $ </td>
</ng-container>

View File

@ -15,11 +15,11 @@ import { ArmorService } from '../../../services/armor.service';
})
export class GameMasterArmorsTableComponent implements OnInit {
displayedColumns: string[] = [
'Name',
'Category',
'MinimumStrength',
'Weight',
'Cost',
'name',
'category',
'minimumStrength',
'weight',
'cost',
];
dataSource: MatTableDataSource<ArmorViewModel>;
@ -40,7 +40,7 @@ export class GameMasterArmorsTableComponent implements OnInit {
if (error instanceof HttpErrorResponse) {
error = error.error as ErrorResponse;
}
console.log(error.message);
console.error(error.message);
}
);
}

View File

@ -20,6 +20,7 @@ import { ClearStore } from '../../store/actions/app.actions';
import { Store } from '@ngrx/store';
import { AppState } from '../../store/models/app-state.model';
import { Router } from '@angular/router';
import { GameMasterMonstersTableComponent } from '../game-master-monsters-table/game-master-monsters-table.component';
@Component({
selector: 'app-game-master-dashboard',
@ -58,6 +59,12 @@ export class GameMasterDashboardComponent implements OnInit, OnDestroy {
componentToDisplay: 'GameMasterSpellsTableComponent',
expanded: false,
},
{
displayName: 'Monsters',
iconName: 'ra ra-wyvern',
componentToDisplay: 'GameMasterMonstersTableComponent',
expanded: false,
},
];
rightSidenavExpanded = false;
@ -132,6 +139,9 @@ export class GameMasterDashboardComponent implements OnInit, OnDestroy {
case 'GameMasterWeaponsTableComponent':
this.middleComponentName = GameMasterWeaponsTableComponent;
break;
case 'GameMasterMonstersTableComponent':
this.middleComponentName = GameMasterMonstersTableComponent;
break;
}
}

View File

@ -0,0 +1,30 @@
table {
background-color: initial;
}
mat-paginator {
background-color: initial;
color: white;
}
::ng-deep .mat-select-arrow {
color: whitesmoke;
}
::ng-deep .mat-select-value {
color: white;
}
.mat-sort-header-container {
color: whitesmoke !important;
}
.mat-form-field {
font-size: 14px;
width: 100%;
}
td,
th {
color: whitesmoke;
}

View File

@ -0,0 +1,48 @@
<mat-form-field>
<mat-label>Filter</mat-label>
<input matInput (keyup)="applyFilter($event)" placeholder="Ex. Dragon" #input>
</mat-form-field>
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort class="w-100">
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
<td mat-cell *matCellDef="let row"> {{row.name}} </td>
</ng-container>
<ng-container matColumnDef="type">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Type </th>
<td mat-cell *matCellDef="let row"> {{row.type.charAt(0).toUpperCase() + row.type.slice(1)}} </td>
</ng-container>
<ng-container matColumnDef="subtype">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Subtype </th>
<td mat-cell *matCellDef="let row"> {{row.subtype ? row.subtype.charAt(0).toUpperCase() + row.subtype.slice(1) : row.subtype}} </td>
</ng-container>
<ng-container matColumnDef="alignment">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Alignment </th>
<td mat-cell *matCellDef="let row"> {{row.alignment ? row.alignment.charAt(0).toUpperCase() + row.alignment.slice(1) : row.alignment}} </td>
</ng-container>
<ng-container matColumnDef="armorClass">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Armor Class </th>
<td mat-cell *matCellDef="let row"> {{row.armorClass}} </td>
</ng-container>
<ng-container matColumnDef="hitPoints">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Hit Points </th>
<td mat-cell *matCellDef="let row"> {{row.hitPoints}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
<tr class="mat-row" *matNoDataRow>
<td class="mat-cell" colspan="4">No data matching the filter "{{input.value}}"</td>
</tr>
</table>
<mat-paginator [pageSizeOptions]="[5, 10, 25, 100]"></mat-paginator>
</div>

View File

@ -0,0 +1,59 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatTableDataSource } from '@angular/material/table';
import { MonsterViewModel } from '../../../types/viewmodels/monster-viewmodels/MonsterViewModel';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { MonsterService } from '../../../services/monster.service';
import { first } from 'rxjs/operators';
import { ErrorResponse } from '../../../types/ErrorResponse';
import { HttpErrorResponse } from '@angular/common/http';
@Component({
selector: 'app-game-master-monsters-table',
templateUrl: './game-master-monsters-table.component.html',
styleUrls: ['./game-master-monsters-table.component.css'],
})
export class GameMasterMonstersTableComponent implements OnInit {
displayedColumns: string[] = [
'name',
'type',
'subtype',
'alignment',
'armorClass',
'hitPoints',
];
dataSource: MatTableDataSource<MonsterViewModel>;
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
@ViewChild(MatSort, { static: true }) sort: MatSort;
constructor(private monsterService: MonsterService) {}
ngOnInit() {
this.monsterService
.GetAllMonsters()
.pipe(first())
.subscribe(
(result) => {
this.dataSource = new MatTableDataSource(result);
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
},
(error: ErrorResponse | HttpErrorResponse) => {
if (error instanceof HttpErrorResponse) {
error = error.error as ErrorResponse;
}
console.error(error.message);
}
);
}
applyFilter(event: Event) {
const filterValue = (event.target as HTMLInputElement).value;
this.dataSource.filter = filterValue.trim().toLowerCase();
if (this.dataSource.paginator) {
this.dataSource.paginator.firstPage();
}
}
}

View File

@ -6,22 +6,22 @@
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="Name">
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
<td mat-cell *matCellDef="let row"> {{row.name}} </td>
</ng-container>
<ng-container matColumnDef="Range">
<ng-container matColumnDef="range">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Range </th>
<td mat-cell *matCellDef="let row"> {{row.range}} </td>
</ng-container>
<ng-container matColumnDef="Level">
<ng-container matColumnDef="level">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Level </th>
<td mat-cell *matCellDef="let row"> {{row.level}} </td>
</ng-container>
<ng-container matColumnDef="School">
<ng-container matColumnDef="school">
<th mat-header-cell *matHeaderCellDef mat-sort-header> School </th>
<td mat-cell *matCellDef="let row"> {{row.school}} </td>
</ng-container>

View File

@ -14,7 +14,7 @@ import { HttpErrorResponse } from '@angular/common/http';
styleUrls: ['./game-master-spells-table.component.css'],
})
export class GameMasterSpellsTableComponent implements OnInit {
displayedColumns: string[] = ['Name', 'Range', 'Level', 'School'];
displayedColumns: string[] = ['name', 'range', 'level', 'school'];
dataSource: MatTableDataSource<SpellViewModel>;
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
@ -34,7 +34,7 @@ export class GameMasterSpellsTableComponent implements OnInit {
if (error instanceof HttpErrorResponse) {
error = error.error as ErrorResponse;
}
console.log(error.message);
console.error(error.message);
}
);
}

View File

@ -6,27 +6,27 @@
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort class="w-100">
<ng-container matColumnDef="Name">
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
<td mat-cell *matCellDef="let row"> {{row.name}} </td>
</ng-container>
<ng-container matColumnDef="WeaponType">
<ng-container matColumnDef="weaponType">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Weapon Type </th>
<td mat-cell *matCellDef="let row"> {{row.weaponType}} </td>
</ng-container>
<ng-container matColumnDef="Weight">
<ng-container matColumnDef="weight">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Weight </th>
<td mat-cell *matCellDef="let row"> {{row.weight}} </td>
</ng-container>
<ng-container matColumnDef="Cost">
<ng-container matColumnDef="cost">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Cost </th>
<td mat-cell *matCellDef="let row"> {{row.cost}} $ </td>
</ng-container>
<ng-container matColumnDef="Description">
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Description </th>
<td mat-cell *matCellDef="let row" class="text-cut" [matTooltip]="row.description">
{{row.description}}

View File

@ -15,11 +15,11 @@ import { HttpErrorResponse } from '@angular/common/http';
})
export class GameMasterWeaponsTableComponent implements OnInit {
displayedColumns: string[] = [
'Name',
'WeaponType',
'Weight',
'Cost',
'Description',
'name',
'weaponType',
'weight',
'cost',
'description',
];
dataSource: MatTableDataSource<WeaponViewModel>;
@ -40,7 +40,7 @@ export class GameMasterWeaponsTableComponent implements OnInit {
if (error instanceof HttpErrorResponse) {
error = error.error as ErrorResponse;
}
console.log(error.message);
console.error(error.message);
}
);
}

View File

@ -0,0 +1,34 @@
import { Inject, Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable, of, throwError } from 'rxjs';
import { SpellViewModel } from '../types/viewmodels/spell-viewmodels/SpellViewModel';
import { Either } from '../types/Either';
import { ErrorResponse } from '../types/ErrorResponse';
import { switchMap } from 'rxjs/operators';
import { MonsterViewModel } from '../types/viewmodels/monster-viewmodels/MonsterViewModel';
Injectable({
providedIn: 'root',
});
export class MonsterService {
private baseUrl = 'api/monster/';
constructor(private http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
this.baseUrl = baseUrl + this.baseUrl;
}
GetAllMonsters(): Observable<MonsterViewModel[]> {
return this.http
.get<Either<MonsterViewModel[], ErrorResponse>>(
this.baseUrl + 'getAllMonsters'
)
.pipe(
switchMap((response) => {
if (response.isLeft) {
return of(response.left);
} else {
return throwError(response.right);
}
})
);
}
}

View File

@ -0,0 +1,35 @@
export interface MonsterViewModel {
id: number;
name: string;
size: string;
type: string;
subtype: string;
alignment: string;
armorClass: number;
hitPoints: number;
hitDiceAmount: number;
hitDiceType: number;
walkSpeed: string;
swimSpeed: string;
flySpeed: string;
dexterity: number;
dexteritySave?: number;
strength: number;
strengthSave?: number;
constitution: number;
constitutionSave?: number;
intelligence: number;
intelligenceSave?: number;
wisdom: number;
wisdomSave?: number;
charisma: number;
charismaSave?: number;
challengeRating: number;
experiencePoints: number;
monsterConditionImmunities: string;
monsterDamageImmunities: string;
monsterDamageResistances: string;
monsterDamageVulnerabilities: string;
monsterLanguages: string;
monsterSenses: string;
}

View File

@ -35,6 +35,7 @@ namespace SessionCompanion.Configurations
services.AddScoped<ICharacterOtherEquipmentService, CharacterOtherEquipmentService>();
services.AddScoped<IWeaponService, WeaponService>();
services.AddScoped<ICharacterWeaponService, CharacterWeaponService>();
services.AddScoped<IMonsterService, MonsterService>();
return services;
}

View File

@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Mvc;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.Services.Interfaces;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using SessionCompanion.ViewModels.ApiResponses;
namespace SessionCompanion.Controllers
{
using SessionCompanion.ViewModels.MonsterViewModels;
[Route("api/monster")]
[ApiController]
public class MonsterController : Controller
{
private readonly IMonsterService _service;
public MonsterController(IMonsterService service) => _service = service;
/// <summary>
/// Metoda zwraca wszystkich przeciwników
/// </summary>
/// <returns>Lista wszystkich przeciwników w bazie danych</returns>
[HttpGet("getAllMonsters")]
public Either<List<MonsterViewModel>, ErrorResponse> GetAllMonsters()
{
try
{
return _service.GetAllMonstersList();
}
catch (Exception e)
{
return new ErrorResponse()
{
StatusCode = 204,
Message = e.Message
};
}
}
}
}