Create shopkeeper endpoint

This commit is contained in:
Łukasz Góreczny 2021-01-22 08:37:31 +01:00
parent e048fe71a3
commit bbf28330e6
3 changed files with 77 additions and 2 deletions

View File

@ -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<ShopkeeperWithItemsDetailsViewModel> {
return this.http
.get<Either<ShopkeeperWithItemsDetailsViewModel, ErrorResponse>>(
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);
}
}

View File

@ -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;
}
];
}

View File

@ -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<Either<SuccessResponse, ErrorResponse>> RemoveShopkeeper([Required] int shopkeeperId)
public async Task<Either<SuccessResponse, ErrorResponse>> RemoveShopkeeper([Required] int shopkeeperId, bool wasAvailable)
{
await this._service.Delete(shopkeeperId);
await this._service.SaveAsync();
if (wasAvailable)
{
await this._sessionHub.Clients.Group("Players").SendAsync("ShopkeeperRemoved");
}
return new SuccessResponse("Delete completed");
}