SES-154 Endpoint zmiany statusu sklepikarza #80
29319
SessionCompanion/SessionCompanion.Database/Migrations/20210120183221_shopkeepers-update.Designer.cs
generated
Normal file
29319
SessionCompanion/SessionCompanion.Database/Migrations/20210120183221_shopkeepers-update.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,41 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace SessionCompanion.Database.Migrations
|
||||||
|
{
|
||||||
|
public partial class shopkeepersupdate : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "Shopkeepers",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: 3,
|
||||||
|
column: "IsAvailable",
|
||||||
|
value: false);
|
||||||
|
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "Shopkeepers",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: 5,
|
||||||
|
column: "IsAvailable",
|
||||||
|
value: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "Shopkeepers",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: 3,
|
||||||
|
column: "IsAvailable",
|
||||||
|
value: true);
|
||||||
|
|
||||||
|
migrationBuilder.UpdateData(
|
||||||
|
table: "Shopkeepers",
|
||||||
|
keyColumn: "Id",
|
||||||
|
keyValue: 5,
|
||||||
|
column: "IsAvailable",
|
||||||
|
value: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -21554,7 +21554,7 @@ namespace SessionCompanion.Database.Migrations
|
|||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = 3,
|
Id = 3,
|
||||||
IsAvailable = true,
|
IsAvailable = false,
|
||||||
Name = "Bohr Twarda Zbroja"
|
Name = "Bohr Twarda Zbroja"
|
||||||
},
|
},
|
||||||
new
|
new
|
||||||
@ -21566,7 +21566,7 @@ namespace SessionCompanion.Database.Migrations
|
|||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = 5,
|
Id = 5,
|
||||||
IsAvailable = true,
|
IsAvailable = false,
|
||||||
Name = "Zielony spod Gruszkowego Lasu"
|
Name = "Zielony spod Gruszkowego Lasu"
|
||||||
},
|
},
|
||||||
new
|
new
|
||||||
|
@ -863,7 +863,7 @@ namespace SessionCompanion.Database
|
|||||||
{
|
{
|
||||||
Id = 3,
|
Id = 3,
|
||||||
Name = "Bohr Twarda Zbroja",
|
Name = "Bohr Twarda Zbroja",
|
||||||
IsAvailable = true
|
IsAvailable = false
|
||||||
},
|
},
|
||||||
new Shopkeeper
|
new Shopkeeper
|
||||||
{
|
{
|
||||||
@ -875,7 +875,7 @@ namespace SessionCompanion.Database
|
|||||||
{
|
{
|
||||||
Id = 5,
|
Id = 5,
|
||||||
Name = "Zielony spod Gruszkowego Lasu",
|
Name = "Zielony spod Gruszkowego Lasu",
|
||||||
IsAvailable = true
|
IsAvailable = false
|
||||||
},
|
},
|
||||||
new Shopkeeper
|
new Shopkeeper
|
||||||
{
|
{
|
||||||
|
@ -14,5 +14,6 @@ namespace SessionCompanion.Services.Interfaces
|
|||||||
public interface IShopkeeperService : IServiceBase<ShopkeeperViewModel, Shopkeeper>
|
public interface IShopkeeperService : IServiceBase<ShopkeeperViewModel, Shopkeeper>
|
||||||
{
|
{
|
||||||
Task<Either<SuccessResponse, ErrorResponse>> CreateNewShopKeeper(ShopkeeperWithItemsViewModel shopkeeperWithItemsViewModel);
|
Task<Either<SuccessResponse, ErrorResponse>> CreateNewShopKeeper(ShopkeeperWithItemsViewModel shopkeeperWithItemsViewModel);
|
||||||
|
Task<Either<SuccessResponse, ErrorResponse>> ChangeShopkeeperStatus(int shopkeeperId, bool availability);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,42 @@ namespace SessionCompanion.Services.Services
|
|||||||
{
|
{
|
||||||
public ShopkeeperService(IMapper mapper, IRepository<Shopkeeper> repository) : base(mapper, repository)
|
public ShopkeeperService(IMapper mapper, IRepository<Shopkeeper> repository) : base(mapper, repository)
|
||||||
{ }
|
{ }
|
||||||
|
/// <summary>
|
||||||
|
/// Funkcja zmienia status sprzedawcy
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="shopkeeperId"></param>
|
||||||
|
/// <param name="availability"></param>
|
||||||
|
/// <returns>SuccesResponse/ErrorResponse</returns>
|
||||||
|
public async Task<Either<SuccessResponse, ErrorResponse>> ChangeShopkeeperStatus(int shopkeeperId, bool availability)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var shopkeepers = await Repository.Get().ToListAsync();
|
||||||
|
if (availability)
|
||||||
|
{
|
||||||
|
foreach (var shopkeeper in shopkeepers)
|
||||||
|
{
|
||||||
|
if (shopkeeper.Id.Equals(shopkeeperId))
|
||||||
|
shopkeeper.IsAvailable = true;
|
||||||
|
else
|
||||||
|
shopkeeper.IsAvailable = false;
|
||||||
|
await Repository.Update(shopkeeper);
|
||||||
|
}
|
||||||
|
await Repository.Save();
|
||||||
|
return new SuccessResponse("Shopkeepers updated") { SuccessCode = 200 };
|
||||||
|
}
|
||||||
|
|
||||||
|
var newActiveShopkeeper = shopkeepers.Where(c => c.Id.Equals(shopkeeperId)).Single();
|
||||||
|
newActiveShopkeeper.IsAvailable = false;
|
||||||
|
await Repository.Update(newActiveShopkeeper);
|
||||||
|
await Repository.Save();
|
||||||
|
return new SuccessResponse("Shopkeepers updated") { SuccessCode = 200 };
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new ErrorResponse() { StatusCode = 500, Message = e.Message };
|
||||||
|
}
|
||||||
|
}
|
||||||
public async Task<Either<SuccessResponse, ErrorResponse>> CreateNewShopKeeper(ShopkeeperWithItemsViewModel shopkeeperWithItemsViewModel)
|
public async Task<Either<SuccessResponse, ErrorResponse>> CreateNewShopKeeper(ShopkeeperWithItemsViewModel shopkeeperWithItemsViewModel)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -12,6 +12,7 @@ namespace SessionCompanion.Controllers
|
|||||||
using SessionCompanion.ViewModels.CharacterArmorViewModels;
|
using SessionCompanion.ViewModels.CharacterArmorViewModels;
|
||||||
using SessionCompanion.ViewModels.CharacterOtherEquipmentViewModels;
|
using SessionCompanion.ViewModels.CharacterOtherEquipmentViewModels;
|
||||||
using SessionCompanion.ViewModels.CharacterWeaponViewModels;
|
using SessionCompanion.ViewModels.CharacterWeaponViewModels;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
[Route("api/character/equipment")]
|
[Route("api/character/equipment")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
@ -38,7 +39,7 @@ namespace SessionCompanion.Controllers
|
|||||||
/// <param name="characterId"> Id postaci </param>
|
/// <param name="characterId"> Id postaci </param>
|
||||||
/// <returns> Lista pozostałego ekwipunku lub błąd </returns>
|
/// <returns> Lista pozostałego ekwipunku lub błąd </returns>
|
||||||
[HttpGet("getOtherEquipment")]
|
[HttpGet("getOtherEquipment")]
|
||||||
public async Task<Either<List<CharacterOtherEquipmentWithDetailsViewModel>, ErrorResponse>> GetCharacterOtherEquipment(int characterId)
|
public async Task<Either<List<CharacterOtherEquipmentWithDetailsViewModel>, ErrorResponse>> GetCharacterOtherEquipment([Required] int characterId)
|
||||||
{
|
{
|
||||||
return await this._characterOtherEquipmentService.GetCharacterOtherEquipmentList(characterId);
|
return await this._characterOtherEquipmentService.GetCharacterOtherEquipmentList(characterId);
|
||||||
}
|
}
|
||||||
@ -49,7 +50,7 @@ namespace SessionCompanion.Controllers
|
|||||||
/// <param name="characterId"> Id postaci </param>
|
/// <param name="characterId"> Id postaci </param>
|
||||||
/// <returns> Lista pozostałego ekwipunku lub błąd </returns>
|
/// <returns> Lista pozostałego ekwipunku lub błąd </returns>
|
||||||
[HttpGet("getArmors")]
|
[HttpGet("getArmors")]
|
||||||
public async Task<Either<List<CharacterArmorViewModelDetails>, ErrorResponse>> GetCharacterArmors(int characterId)
|
public async Task<Either<List<CharacterArmorViewModelDetails>, ErrorResponse>> GetCharacterArmors([Required] int characterId)
|
||||||
{
|
{
|
||||||
return await this._characterArmorService.GetCharacterArmorsTaskList(characterId);
|
return await this._characterArmorService.GetCharacterArmorsTaskList(characterId);
|
||||||
}
|
}
|
||||||
@ -60,7 +61,7 @@ namespace SessionCompanion.Controllers
|
|||||||
/// <param name="characterId"> Id postaci </param>
|
/// <param name="characterId"> Id postaci </param>
|
||||||
/// <returns> Lista broni lub błąd </returns>
|
/// <returns> Lista broni lub błąd </returns>
|
||||||
[HttpGet("getWeapons")]
|
[HttpGet("getWeapons")]
|
||||||
public async Task<Either<List<CharacterWeaponWithWeaponDetailsViewModel>, ErrorResponse>> GetCharacterWeapons(int characterId)
|
public async Task<Either<List<CharacterWeaponWithWeaponDetailsViewModel>, ErrorResponse>> GetCharacterWeapons([Required] int characterId)
|
||||||
{
|
{
|
||||||
return await this._characterWeaponService.GetCharacterWeaponsList(characterId);
|
return await this._characterWeaponService.GetCharacterWeaponsList(characterId);
|
||||||
}
|
}
|
||||||
@ -72,7 +73,7 @@ namespace SessionCompanion.Controllers
|
|||||||
/// <param name="newArmorId"> Id nowej zbroi </param>
|
/// <param name="newArmorId"> Id nowej zbroi </param>
|
||||||
/// <returns>SuccessResponse/ErrorResponse</returns>
|
/// <returns>SuccessResponse/ErrorResponse</returns>
|
||||||
[HttpPut("changeArmor")]
|
[HttpPut("changeArmor")]
|
||||||
public async Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterArmor(int characterId, int newArmorId)
|
public async Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterArmor([Required] int characterId, [Required] int newArmorId)
|
||||||
{
|
{
|
||||||
var response = await _characterArmorService.ChangeCharacterArmor(characterId, newArmorId);
|
var response = await _characterArmorService.ChangeCharacterArmor(characterId, newArmorId);
|
||||||
return response;
|
return response;
|
||||||
@ -84,7 +85,7 @@ namespace SessionCompanion.Controllers
|
|||||||
/// <param name="characterArmorViewModel"> View model z odpowiednimi parameterami </param>
|
/// <param name="characterArmorViewModel"> View model z odpowiednimi parameterami </param>
|
||||||
/// <returns>SuccessResponse/ErrorResponse</returns>
|
/// <returns>SuccessResponse/ErrorResponse</returns>
|
||||||
[HttpPut("addArmor")]
|
[HttpPut("addArmor")]
|
||||||
public async Task<Either<SuccessResponse, ErrorResponse>> AddCharacterArmor(CharacterArmorViewModel characterArmorViewModel)
|
public async Task<Either<SuccessResponse, ErrorResponse>> AddCharacterArmor([Required] CharacterArmorViewModel characterArmorViewModel)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" };
|
return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" };
|
||||||
@ -106,7 +107,7 @@ namespace SessionCompanion.Controllers
|
|||||||
/// <param name="characterWeaponViewModel"> View model z odpowiednimi parameterami </param>
|
/// <param name="characterWeaponViewModel"> View model z odpowiednimi parameterami </param>
|
||||||
/// <returns>SuccessResponse/ErrorResponse</returns>
|
/// <returns>SuccessResponse/ErrorResponse</returns>
|
||||||
[HttpPut("addWeapon")]
|
[HttpPut("addWeapon")]
|
||||||
public async Task<Either<SuccessResponse, ErrorResponse>> AddCharacterWeapon(CharacterWeaponViewModel characterWeaponViewModel)
|
public async Task<Either<SuccessResponse, ErrorResponse>> AddCharacterWeapon([Required] CharacterWeaponViewModel characterWeaponViewModel)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" };
|
return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" };
|
||||||
@ -127,7 +128,7 @@ namespace SessionCompanion.Controllers
|
|||||||
/// <param name=characterWeaponViewModel> View model z odpowiednimi parameterami </param>
|
/// <param name=characterWeaponViewModel> View model z odpowiednimi parameterami </param>
|
||||||
/// <returns>SuccessResponse/ErrorResponse</returns>
|
/// <returns>SuccessResponse/ErrorResponse</returns>
|
||||||
[HttpPut("changeWeapon")]
|
[HttpPut("changeWeapon")]
|
||||||
public async Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterWeapon(CharacterWeaponViewModel characterWeaponViewModel)
|
public async Task<Either<SuccessResponse, ErrorResponse>> ChangeCharacterWeapon([Required] CharacterWeaponViewModel characterWeaponViewModel)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" };
|
return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" };
|
||||||
|
@ -31,12 +31,16 @@ namespace SessionCompanion.Controllers
|
|||||||
return _service.Get().ToList();
|
return _service.Get().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("createNewShopkeeper")]
|
/// <summary>
|
||||||
public async Task<Either<SuccessResponse, ErrorResponse>> CreateNewShopKeeper([Required] ShopkeeperWithItemsViewModel shopkeeperWithItemsViewModel)
|
/// Endpoint służacy do zmiany statusu sklepikarza
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="shopkeeperId"></param>
|
||||||
|
/// <param name="availability"></param>
|
||||||
|
/// <returns>SuccesResponse/ErrorResponse</returns>
|
||||||
|
[HttpPut("changeShopkeeperStatus")]
|
||||||
|
public async Task<Either<SuccessResponse, ErrorResponse>> ChangeShopkeeperStatus([Required] int shopkeeperId, [Required] bool availability)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
return await _service.ChangeShopkeeperStatus(shopkeeperId, availability);
|
||||||
return new ErrorResponse() { StatusCode = 500, Message = "Model is invalid" };
|
|
||||||
return await _service.CreateNewShopKeeper(shopkeeperWithItemsViewModel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user