diff --git a/SessionCompanion/SessionCompanion.Services/Intefraces/IMonsterService.cs b/SessionCompanion/SessionCompanion.Services/Intefraces/IMonsterService.cs new file mode 100644 index 0000000..303f7d5 --- /dev/null +++ b/SessionCompanion/SessionCompanion.Services/Intefraces/IMonsterService.cs @@ -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 + { + List GetAllMonstersList(); + } +} \ No newline at end of file diff --git a/SessionCompanion/SessionCompanion.Services/Profiles/MonsterProfile.cs b/SessionCompanion/SessionCompanion.Services/Profiles/MonsterProfile.cs new file mode 100644 index 0000000..06c15df --- /dev/null +++ b/SessionCompanion/SessionCompanion.Services/Profiles/MonsterProfile.cs @@ -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().ReverseMap(); + } + } +} \ No newline at end of file diff --git a/SessionCompanion/SessionCompanion.Services/Services/MonsterService.cs b/SessionCompanion/SessionCompanion.Services/Services/MonsterService.cs new file mode 100644 index 0000000..106b6b3 --- /dev/null +++ b/SessionCompanion/SessionCompanion.Services/Services/MonsterService.cs @@ -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, IMonsterService + { + public MonsterService(IMapper mapper, IRepository repository) : base(mapper, repository) + { } + + public List GetAllMonstersList() + { + var monsters = this.Repository.Get(); + + return this.Mapper.Map>(monsters); + } + } +} \ No newline at end of file diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts index ab57d47..6494584 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/app.module.ts @@ -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, ], diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-armors-table/game-master-armors-table.component.html b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-armors-table/game-master-armors-table.component.html index de8cbe6..e981e6d 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-armors-table/game-master-armors-table.component.html +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-armors-table/game-master-armors-table.component.html @@ -6,27 +6,27 @@
- + - + - + - + - + diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-armors-table/game-master-armors-table.component.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-armors-table/game-master-armors-table.component.ts index 74bbd25..39286a7 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-armors-table/game-master-armors-table.component.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-armors-table/game-master-armors-table.component.ts @@ -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; @@ -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); } ); } diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-dashboard/game-master-dashboard.component.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-dashboard/game-master-dashboard.component.ts index 364948c..4367adb 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-dashboard/game-master-dashboard.component.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-dashboard/game-master-dashboard.component.ts @@ -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; } } diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-monsters-table/game-master-monsters-table.component.css b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-monsters-table/game-master-monsters-table.component.css new file mode 100644 index 0000000..13a396c --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-monsters-table/game-master-monsters-table.component.css @@ -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; +} diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-monsters-table/game-master-monsters-table.component.html b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-monsters-table/game-master-monsters-table.component.html new file mode 100644 index 0000000..b0f3ac5 --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-monsters-table/game-master-monsters-table.component.html @@ -0,0 +1,48 @@ + + Filter + + + +
+
Name {{row.name}} Category {{row.category}} Minimum Strength {{row.minimumStrength}}% Weight {{row.weight}} Cost {{row.cost}} $
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name {{row.name}} Type {{row.type.charAt(0).toUpperCase() + row.type.slice(1)}} Subtype {{row.subtype ? row.subtype.charAt(0).toUpperCase() + row.subtype.slice(1) : row.subtype}} Alignment {{row.alignment ? row.alignment.charAt(0).toUpperCase() + row.alignment.slice(1) : row.alignment}} Armor Class {{row.armorClass}} Hit Points {{row.hitPoints}}
No data matching the filter "{{input.value}}"
+ + +
diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-monsters-table/game-master-monsters-table.component.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-monsters-table/game-master-monsters-table.component.ts new file mode 100644 index 0000000..8bc8643 --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-monsters-table/game-master-monsters-table.component.ts @@ -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; + + @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(); + } + } +} diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-spells-table/game-master-spells-table.component.html b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-spells-table/game-master-spells-table.component.html index bcbc20f..b8512dd 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-spells-table/game-master-spells-table.component.html +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-spells-table/game-master-spells-table.component.html @@ -6,22 +6,22 @@
- + - + - + - + diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-spells-table/game-master-spells-table.component.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-spells-table/game-master-spells-table.component.ts index 7005445..a576645 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-spells-table/game-master-spells-table.component.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-spells-table/game-master-spells-table.component.ts @@ -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; @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); } ); } diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.html b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.html index a7855d1..a90baa4 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.html +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.html @@ -6,27 +6,27 @@
Name {{row.name}} Range {{row.range}} Level {{row.level}} School {{row.school}}
- + - + - + - + - +
Name {{row.name}} Weapon Type {{row.weaponType}} Weight {{row.weight}} Cost {{row.cost}} $ Description {{row.description}} diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.ts index e4e3497..b377c0c 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/components/game-master-weapons-table/game-master-weapons-table.component.ts @@ -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; @@ -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); } ); } diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/services/monster.service.ts b/SessionCompanion/SessionCompanion/ClientApp/src/services/monster.service.ts new file mode 100644 index 0000000..04c0d1c --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/services/monster.service.ts @@ -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 { + return this.http + .get>( + this.baseUrl + 'getAllMonsters' + ) + .pipe( + switchMap((response) => { + if (response.isLeft) { + return of(response.left); + } else { + return throwError(response.right); + } + }) + ); + } +} diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/types/viewmodels/monster-viewmodels/MonsterViewModel.ts b/SessionCompanion/SessionCompanion/ClientApp/src/types/viewmodels/monster-viewmodels/MonsterViewModel.ts new file mode 100644 index 0000000..9b666f7 --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/types/viewmodels/monster-viewmodels/MonsterViewModel.ts @@ -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; +} diff --git a/SessionCompanion/SessionCompanion/Configurations/ServiceConfiguration.cs b/SessionCompanion/SessionCompanion/Configurations/ServiceConfiguration.cs index f01a70e..8b354a8 100644 --- a/SessionCompanion/SessionCompanion/Configurations/ServiceConfiguration.cs +++ b/SessionCompanion/SessionCompanion/Configurations/ServiceConfiguration.cs @@ -35,6 +35,7 @@ namespace SessionCompanion.Configurations services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); return services; } diff --git a/SessionCompanion/SessionCompanion/Controllers/MonsterController.cs b/SessionCompanion/SessionCompanion/Controllers/MonsterController.cs new file mode 100644 index 0000000..8d50c07 --- /dev/null +++ b/SessionCompanion/SessionCompanion/Controllers/MonsterController.cs @@ -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; + + /// + /// Metoda zwraca wszystkich przeciwników + /// + /// Lista wszystkich przeciwników w bazie danych + [HttpGet("getAllMonsters")] + public Either, ErrorResponse> GetAllMonsters() + { + try + { + return _service.GetAllMonstersList(); + } + catch (Exception e) + { + return new ErrorResponse() + { + StatusCode = 204, + Message = e.Message + }; + } + } + } +} \ No newline at end of file