From bbf28330e6fe13bb5272f922d190dc4a96409805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20G=C3=B3reczny?= Date: Fri, 22 Jan 2021 08:37:31 +0100 Subject: [PATCH] Create shopkeeper endpoint --- .../src/services/shopkeeper.service.ts | 25 +++++++++++ .../ShopkeeperWithItemsDetailsViewModel.ts | 43 +++++++++++++++++++ .../Controllers/ShopkeeperController.cs | 11 ++++- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 SessionCompanion/SessionCompanion/ClientApp/src/types/viewmodels/shopkeeper-viewmodels/ShopkeeperWithItemsDetailsViewModel.ts diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/services/shopkeeper.service.ts b/SessionCompanion/SessionCompanion/ClientApp/src/services/shopkeeper.service.ts index 2ac9a1e..e3f8cf6 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/src/services/shopkeeper.service.ts +++ b/SessionCompanion/SessionCompanion/ClientApp/src/services/shopkeeper.service.ts @@ -6,6 +6,7 @@ import { Either } from '../types/Either'; import { ErrorResponse } from '../types/ErrorResponse'; import { switchMap } from 'rxjs/operators'; import { SuccessResponse } from '../types/SuccessResponse'; +import { ShopkeeperWithItemsDetailsViewModel } from '../types/viewmodels/shopkeeper-viewmodels/ShopkeeperWithItemsDetailsViewModel'; Injectable({ providedIn: 'root', @@ -33,10 +34,34 @@ export class ShopkeeperService { ); } + GetActiveShopkeeper(): Observable { + return this.http + .get>( + this.baseUrl + 'getActiveShopkeeper' + ) + .pipe( + switchMap((response) => { + debugger; + if (response.isLeft) { + return of(response.left); + } else { + return throwError(response.right); + } + }) + ); + } + ChangeShopkeeperStatus(shopkeeperId: number, newStatus: boolean) { const params = new HttpParams() .set('shopkeeperId', shopkeeperId.toString()) .set('availability', newStatus.toString()); this.http.post(this.baseUrl + 'getShopkeepers', params); } + + RemoveShopkeeper(shopkeeperId: number, currentStatus: boolean) { + const params = new HttpParams() + .set('shopkeeperId', shopkeeperId.toString()) + .set('wasAvailable', currentStatus.toString()); + this.http.post(this.baseUrl + 'getShopkeepers', params); + } } diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/types/viewmodels/shopkeeper-viewmodels/ShopkeeperWithItemsDetailsViewModel.ts b/SessionCompanion/SessionCompanion/ClientApp/src/types/viewmodels/shopkeeper-viewmodels/ShopkeeperWithItemsDetailsViewModel.ts new file mode 100644 index 0000000..377ed2f --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/types/viewmodels/shopkeeper-viewmodels/ShopkeeperWithItemsDetailsViewModel.ts @@ -0,0 +1,43 @@ +export interface ShopkeeperWithItemsDetailsViewModel { + id: number; + name: string; + isAvailable: boolean; + items: [ + { + shopkeeperId: number; + armorId: number; + armor: { + id: number; + name: string; + category: string; + armorClassBase: string; + haveDexterityBonus: true; + minimumStrength: number; + haveStealthDisadvantage: boolean; + weight: number; + cost: number; + currencyType: number; + }; + weaponId: number; + weapon: { + id: number; + name: string; + cost: number; + weight: number; + currencyType: number; + diceCount: number; + diceValue: number; + twoHandDiceCount: number; + twoHandDiceValue: number; + twoHandDamageType: string; + description: string; + weaponType: string; + rangeMeele: number; + rangeThrowNormal: number; + rangeThrowLong: number; + rangeLong: number; + }; + amount: number; + } + ]; +} diff --git a/SessionCompanion/SessionCompanion/Controllers/ShopkeeperController.cs b/SessionCompanion/SessionCompanion/Controllers/ShopkeeperController.cs index f277311..0a05544 100644 --- a/SessionCompanion/SessionCompanion/Controllers/ShopkeeperController.cs +++ b/SessionCompanion/SessionCompanion/Controllers/ShopkeeperController.cs @@ -62,6 +62,10 @@ namespace SessionCompanion.Controllers { await this._sessionHub.Clients.Group("Players").SendAsync("NewShopkeeperArrived"); } + else + { + await this._sessionHub.Clients.Group("Players").SendAsync("ShopkeeperLeft"); + } return result; } @@ -75,12 +79,15 @@ namespace SessionCompanion.Controllers } [HttpPost("removeShopkeeper")] - public async Task> RemoveShopkeeper([Required] int shopkeeperId) + public async Task> RemoveShopkeeper([Required] int shopkeeperId, bool wasAvailable) { await this._service.Delete(shopkeeperId); await this._service.SaveAsync(); - await this._sessionHub.Clients.Group("Players").SendAsync("ShopkeeperRemoved"); + if (wasAvailable) + { + await this._sessionHub.Clients.Group("Players").SendAsync("ShopkeeperRemoved"); + } return new SuccessResponse("Delete completed"); }