From 95b995fd2db6e43a64ea60b61cf0fb6b619a1383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Tue, 12 Jan 2021 23:27:59 +0100 Subject: [PATCH 1/9] SES-148 Add Armor changing, but not ready yet --- .../Services/CharacterArmorService.cs | 39 +++++++++++++++++++ SessionCompanion/SessionCompanion.sln | 5 ++- .../Controllers/CharacterArmorController.cs | 33 ++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 SessionCompanion/SessionCompanion/Controllers/CharacterArmorController.cs diff --git a/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs b/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs index 8b417dd..75b4594 100644 --- a/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs +++ b/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs @@ -15,11 +15,50 @@ namespace SessionCompanion.Services.Services using SessionCompanion.Database.Tables; using SessionCompanion.Services.Base; using SessionCompanion.Services.Interfaces; + using SessionCompanion.ViewModels.ApiResponses; using SessionCompanion.ViewModels.CharacterArmorViewModels; public class CharacterArmorService : ServiceBase, ICharacterArmorService { public CharacterArmorService(IMapper mapper, IRepository repository) : base(mapper, repository) { } + public async Task> ChangeCharacterArmor(int characterId, int newArmorId) + { + var armorInUse = await Repository.Get(c => c.CharacterId.Equals(characterId)) + .Include(a => a.Armor).Where(x => x.InUse == true).SingleAsync(); + var armorToUse = await Repository.Get(c => c.ArmorId.Equals(newArmorId) && c.CharacterId.Equals(characterId)).SingleAsync(); + + if (armorToUse is null) + return new ErrorResponse() { StatusCode = 204, Message = "No weapon to change to" }; + + if (armorInUse is null) + { + armorToUse.InUse = true; + try + { + await Repository.Update(armorToUse); + await Repository.Save(); + return new SuccessResponse("Character weapon updated") { SuccessCode = 200 }; + } + catch (Exception e) + { + return new ErrorResponse() { StatusCode = 500, Message = e.Message }; + } + } + + armorInUse.InUse = false; + armorToUse.InUse = true; + try + { + await Repository.Update(armorInUse); + await Repository.Update(armorToUse); + await Repository.Save(); + return new SuccessResponse("Character weapon updated") { SuccessCode = 204 } + } + catch (Exception e) + { + return new ErrorResponse() { StatusCode = 500, Message = e.Message }; + } + } } } diff --git a/SessionCompanion/SessionCompanion.sln b/SessionCompanion/SessionCompanion.sln index 728a6b1..6153d19 100644 --- a/SessionCompanion/SessionCompanion.sln +++ b/SessionCompanion/SessionCompanion.sln @@ -10,10 +10,13 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.ViewModels", "SessionCompanion.ViewModels\SessionCompanion.ViewModels.csproj", "{7762AA75-7B60-4F28-B80A-B03E39140F89}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.Services", "SessionCompanion.Services\SessionCompanion.Services.csproj", "{C0A172ED-0F4C-4E78-8B64-28E2A756F62F}" + ProjectSection(ProjectDependencies) = postProject + {1EE35EB3-C703-407C-B390-5605A0A46884} = {1EE35EB3-C703-407C-B390-5605A0A46884} + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.Extensions", "SessionCompanion.Extensions\SessionCompanion.Extensions.csproj", "{1EE35EB3-C703-407C-B390-5605A0A46884}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SessionCompanion.XUnitTests", "SessionCompanion.XUnitTests\SessionCompanion.XUnitTests.csproj", "{B8A4DAF6-DD33-4B35-99B8-A1D060EE1869}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionCompanion.XUnitTests", "SessionCompanion.XUnitTests\SessionCompanion.XUnitTests.csproj", "{B8A4DAF6-DD33-4B35-99B8-A1D060EE1869}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/SessionCompanion/SessionCompanion/Controllers/CharacterArmorController.cs b/SessionCompanion/SessionCompanion/Controllers/CharacterArmorController.cs new file mode 100644 index 0000000..22ca01d --- /dev/null +++ b/SessionCompanion/SessionCompanion/Controllers/CharacterArmorController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; +using SessionCompanion.Services.Interfaces; +using SessionCompanion.Extensions.EitherType; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using SessionCompanion.ViewModels.ApiResponses; + +namespace SessionCompanion.Controllers +{ + [Route("api/characterArmor")] + [ApiController] + public class CharacterArmorController : Controller + { + private ICharacterArmorService _service; + public CharacterArmorController(ICharacterArmorService characterArmorService) + { + this._service = characterArmorService; + } + + /// + /// Metoda zmienia uzywany armor danej postaci + /// + /// + /// + /// + public async Task> ChangeCharacterArmor(int characterId, int newArmorId) + { + return new ErrorResponse() { StatusCode = 1, Message = "asd" }; + } + } +} -- 2.20.1 From 09863e9b8e17dbc421b4de54a55bdf7d656e1c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20G=C3=B3reczny?= Date: Wed, 13 Jan 2021 09:37:20 +0100 Subject: [PATCH 2/9] SES-148 Added reference --- .../Services/CharacterArmorService.cs | 3 ++- .../SessionCompanion.Services/SessionCompanion.Services.csproj | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs b/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs index 75b4594..f23d8a4 100644 --- a/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs +++ b/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs @@ -17,6 +17,7 @@ namespace SessionCompanion.Services.Services using SessionCompanion.Services.Interfaces; using SessionCompanion.ViewModels.ApiResponses; using SessionCompanion.ViewModels.CharacterArmorViewModels; + using SessionCompanion.Extensions.EitherType; public class CharacterArmorService : ServiceBase, ICharacterArmorService { @@ -53,7 +54,7 @@ namespace SessionCompanion.Services.Services await Repository.Update(armorInUse); await Repository.Update(armorToUse); await Repository.Save(); - return new SuccessResponse("Character weapon updated") { SuccessCode = 204 } + return new SuccessResponse("Character weapon updated") { SuccessCode = 204 }; } catch (Exception e) { diff --git a/SessionCompanion/SessionCompanion.Services/SessionCompanion.Services.csproj b/SessionCompanion/SessionCompanion.Services/SessionCompanion.Services.csproj index a6d012a..d8f9df8 100644 --- a/SessionCompanion/SessionCompanion.Services/SessionCompanion.Services.csproj +++ b/SessionCompanion/SessionCompanion.Services/SessionCompanion.Services.csproj @@ -10,6 +10,7 @@ + -- 2.20.1 From 108dc89fd7a4ce04b763f057acd927b2a78f0ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Wed, 13 Jan 2021 17:10:41 +0100 Subject: [PATCH 3/9] SES-148 finished character armor --- .../Intefraces/ICharacterArmorService.cs | 3 +++ .../Services/CharacterArmorService.cs | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterArmorService.cs b/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterArmorService.cs index 08f0382..7106bd8 100644 --- a/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterArmorService.cs +++ b/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterArmorService.cs @@ -7,10 +7,13 @@ namespace SessionCompanion.Services.Interfaces using System.Threading.Tasks; using SessionCompanion.Database.Tables; + using SessionCompanion.Extensions.EitherType; using SessionCompanion.Services.Base; + using SessionCompanion.ViewModels.ApiResponses; using SessionCompanion.ViewModels.CharacterArmorViewModels; public interface ICharacterArmorService : IServiceBase { + Task> ChangeCharacterArmor(int characterId, int newArmorId); } } diff --git a/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs b/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs index f23d8a4..3eaaf16 100644 --- a/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs +++ b/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs @@ -25,9 +25,18 @@ namespace SessionCompanion.Services.Services { } public async Task> ChangeCharacterArmor(int characterId, int newArmorId) { - var armorInUse = await Repository.Get(c => c.CharacterId.Equals(characterId)) - .Include(a => a.Armor).Where(x => x.InUse == true).SingleAsync(); - var armorToUse = await Repository.Get(c => c.ArmorId.Equals(newArmorId) && c.CharacterId.Equals(characterId)).SingleAsync(); + CharacterArmor armorInUse = new CharacterArmor(); + CharacterArmor armorToUse = new CharacterArmor(); + try + { + armorInUse = await Repository.Get(c => c.CharacterId.Equals(characterId)) + .Include(a => a.Armor).Where(x => x.InUse == true).SingleAsync(); + armorToUse = await Repository.Get(c => c.ArmorId.Equals(newArmorId) && c.CharacterId.Equals(characterId)).SingleAsync(); + } + catch (Exception e) + { + return new ErrorResponse() { StatusCode = 500, Message = e.Message }; + } if (armorToUse is null) return new ErrorResponse() { StatusCode = 204, Message = "No weapon to change to" }; -- 2.20.1 From 8a7c50b30762b51a61249099ad8b6c95c6125275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Wed, 13 Jan 2021 17:29:03 +0100 Subject: [PATCH 4/9] SES-148 Change endpoint location --- .../Controllers/CharacterArmorController.cs | 33 ---------------- .../Controllers/EquipmentController.cs | 38 +++++++++++++++++-- 2 files changed, 35 insertions(+), 36 deletions(-) delete mode 100644 SessionCompanion/SessionCompanion/Controllers/CharacterArmorController.cs diff --git a/SessionCompanion/SessionCompanion/Controllers/CharacterArmorController.cs b/SessionCompanion/SessionCompanion/Controllers/CharacterArmorController.cs deleted file mode 100644 index 22ca01d..0000000 --- a/SessionCompanion/SessionCompanion/Controllers/CharacterArmorController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using SessionCompanion.Services.Interfaces; -using SessionCompanion.Extensions.EitherType; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using SessionCompanion.ViewModels.ApiResponses; - -namespace SessionCompanion.Controllers -{ - [Route("api/characterArmor")] - [ApiController] - public class CharacterArmorController : Controller - { - private ICharacterArmorService _service; - public CharacterArmorController(ICharacterArmorService characterArmorService) - { - this._service = characterArmorService; - } - - /// - /// Metoda zmienia uzywany armor danej postaci - /// - /// - /// - /// - public async Task> ChangeCharacterArmor(int characterId, int newArmorId) - { - return new ErrorResponse() { StatusCode = 1, Message = "asd" }; - } - } -} diff --git a/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs b/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs index ef1fd92..b27145c 100644 --- a/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs +++ b/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs @@ -17,7 +17,7 @@ namespace SessionCompanion.Controllers [ApiController] public class EquipmentController : Controller { - private readonly ICharacterArmorService _characterArmorServic; + private readonly ICharacterArmorService _characterArmorService; private readonly ICharacterOtherEquipmentService _characterOtherEquipmentService; @@ -27,7 +27,7 @@ namespace SessionCompanion.Controllers ICharacterOtherEquipmentService characterOtherEquipmentService, ICharacterWeaponService characterWeaponService) { - this._characterArmorServic = characterArmorService; + this._characterArmorService = characterArmorService; this._characterOtherEquipmentService = characterOtherEquipmentService; this._characterWeaponService = characterWeaponService; } @@ -51,7 +51,7 @@ namespace SessionCompanion.Controllers [HttpGet("getArmors")] public async Task, ErrorResponse>> GetCharacterArmors(int characterId) { - return await this._characterArmorServic.GetCharacterArmorsTaskList(characterId); + return await this._characterArmorService.GetCharacterArmorsTaskList(characterId); } /// @@ -65,5 +65,37 @@ namespace SessionCompanion.Controllers return await this._characterWeaponService.GetCharacterWeaponsList(characterId); } + /// + /// Metoda zmienia uzywany armor danej postaci + /// + /// + /// + /// + [HttpPut("changeArmor")] + public async Task> ChangeCharacterArmor(int characterId, int newArmorId) + { + var response = await _characterArmorService.ChangeCharacterArmor(characterId, newArmorId); + return response; + } + + /// + /// Metoda dodaje Armor do danej postaci + /// + /// + /// + [HttpPut("addArmor")] + public async Task> AddCharacterArmor(CharacterArmorViewModel characterArmorViewModel) + { + try + { + await _characterArmorService.Create(characterArmorViewModel); + await _characterArmorService.SaveAsync(); + return new SuccessResponse("Armor added to character") { SuccessCode = 200 }; + } + catch (Exception e) + { + return new ErrorResponse() { StatusCode = 500, Message = e.Message }; + } + } } } -- 2.20.1 From 3ca90663b285a7797dcd6aaee035126aa039c301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Wed, 13 Jan 2021 17:37:25 +0100 Subject: [PATCH 5/9] SES-148 Add Endpoint to add new weapon to character --- .../Controllers/EquipmentController.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs b/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs index b27145c..7793804 100644 --- a/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs +++ b/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs @@ -97,5 +97,26 @@ namespace SessionCompanion.Controllers return new ErrorResponse() { StatusCode = 500, Message = e.Message }; } } + /// + /// Metoda dodaje Weapon do danej postaci + /// + /// + /// + [HttpPut("addWeapon")] + public async Task> AddCharacterWeapon(CharacterWeaponViewModel characterWeaponViewModel) + { + if (!ModelState.IsValid) + return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" }; + try + { + await _characterWeaponService.Create(characterWeaponViewModel); + await _characterWeaponService.SaveAsync(); + return new SuccessResponse("Weapon added to character") { SuccessCode = 200 }; + } + catch (Exception e) + { + return new ErrorResponse() { StatusCode = 500, Message = e.Message }; + } + } } } -- 2.20.1 From 71f01a167c37f026b380e6c33988e2f363a6d625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Wed, 13 Jan 2021 19:29:32 +0100 Subject: [PATCH 6/9] SES-148 Add changing weapoin mechanic --- .../Intefraces/ICharacterWeaponService.cs | 3 + .../Services/CharacterWeaponService.cs | 58 +++++++++++++++++++ .../Controllers/EquipmentController.cs | 19 ++++++ 3 files changed, 80 insertions(+) diff --git a/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterWeaponService.cs b/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterWeaponService.cs index 8206eb9..ff02169 100644 --- a/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterWeaponService.cs +++ b/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterWeaponService.cs @@ -4,11 +4,14 @@ using SessionCompanion.ViewModels.CharacterWeaponViewModels; namespace SessionCompanion.Services.Interfaces { + using SessionCompanion.Extensions.EitherType; + using SessionCompanion.ViewModels.ApiResponses; using System.Collections.Generic; using System.Threading.Tasks; public interface ICharacterWeaponService : IServiceBase { Task> GetCharacterWeaponsList(int characterId); + Task> ChangeCharacterWeapon(CharacterWeaponViewModel model); } } diff --git a/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs b/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs index 2e54b32..cc840e0 100644 --- a/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs +++ b/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs @@ -12,6 +12,8 @@ namespace SessionCompanion.Services.Services using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; + using SessionCompanion.Extensions.EitherType; + using SessionCompanion.ViewModels.ApiResponses; public class CharacterWeaponService : ServiceBase, ICharacterWeaponService { @@ -30,5 +32,61 @@ namespace SessionCompanion.Services.Services var result = Mapper.Map>(characterWeapons); return result; } + + public async Task> ChangeCharacterWeapon(CharacterWeaponViewModel model) + { + // Dodaj optional rozbro postac + var weaponsInUse = await Repository.Get(c => c.CharacterId.Equals(model.CharacterId)).Where(w => w.InUse.Equals(true)).ToListAsync(); + + var weapon = Mapper.Map(model); + + if (weaponsInUse.Count() == 0) + { + // no weapon in use + // just use new one + await Repository.Update(weapon); + await Repository.Save(); + return new SuccessResponse("Weapon changed") { SuccessCode = 200 }; + } + + var weaponInBothHands = weaponsInUse.Where(w => w.HoldInLeftHand.Equals(true) && w.HoldInRightHand.Equals(true)); + + if ((model.HoldInLeftHand && model.HoldInRightHand) || (weaponInBothHands.Count() > 0)) + { + // our model weapon uses both hands + // or there is weapon already in both hands + foreach (var w in weaponsInUse) + { + w.InUse = false; + w.HoldInLeftHand = false; + w.HoldInRightHand = false; + await Repository.Update(w); + } + + await Repository.Update(weapon); + await Repository.Save(); + return new SuccessResponse("Weapon changed") { SuccessCode = 200 }; + } + + var weaponsToChange = weaponsInUse.Where(w => w.HoldInLeftHand.Equals(model.HoldInLeftHand) && w.HoldInRightHand.Equals(model.HoldInRightHand)); + if (weaponsToChange.Count() == 1) + { + // there is weapon in the same hand set as our + // we update it + var weaponToChange = weaponsToChange.Single(); + weaponToChange.InUse = false; + weaponToChange.HoldInLeftHand = false; + weaponToChange.HoldInRightHand = false; + await Repository.Update(weaponToChange); + await Repository.Update(weapon); + await Repository.Save(); + return new SuccessResponse("Weapon changed") { SuccessCode = 200 }; + } + + // weapon is armed in empty hand + await Repository.Update(weapon); + await Repository.Save(); + return new SuccessResponse("Weapon changed") { SuccessCode = 200 }; + } } } diff --git a/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs b/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs index 7793804..ac6fee8 100644 --- a/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs +++ b/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs @@ -86,6 +86,8 @@ namespace SessionCompanion.Controllers [HttpPut("addArmor")] public async Task> AddCharacterArmor(CharacterArmorViewModel characterArmorViewModel) { + if (!ModelState.IsValid) + return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" }; try { await _characterArmorService.Create(characterArmorViewModel); @@ -97,6 +99,7 @@ namespace SessionCompanion.Controllers return new ErrorResponse() { StatusCode = 500, Message = e.Message }; } } + /// /// Metoda dodaje Weapon do danej postaci /// @@ -118,5 +121,21 @@ namespace SessionCompanion.Controllers return new ErrorResponse() { StatusCode = 500, Message = e.Message }; } } + + [HttpPut("changeWeapon")] + public async Task> ChangeCharacterWeapon(CharacterWeaponViewModel characterWeaponViewModel) + { + if (!ModelState.IsValid) + return new ErrorResponse() { StatusCode = 500, Message = "Invalid model!" }; + try + { + var response = await _characterWeaponService.ChangeCharacterWeapon(characterWeaponViewModel); + return response; + } + catch (Exception e) + { + return new ErrorResponse() { StatusCode = 500, Message = e.Message }; + } + } } } -- 2.20.1 From ad92ad468b45b9fcc3061415b3a79010c76e7faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Wed, 13 Jan 2021 20:24:10 +0100 Subject: [PATCH 7/9] SES-148 CharacterWeaponViewModel doesnt need valid ID anymore --- .../Services/CharacterWeaponService.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs b/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs index cc840e0..01addda 100644 --- a/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs +++ b/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs @@ -36,9 +36,12 @@ namespace SessionCompanion.Services.Services public async Task> ChangeCharacterWeapon(CharacterWeaponViewModel model) { // Dodaj optional rozbro postac - var weaponsInUse = await Repository.Get(c => c.CharacterId.Equals(model.CharacterId)).Where(w => w.InUse.Equals(true)).ToListAsync(); - + var allWeapons = await Repository.Get(c => c.CharacterId.Equals(model.CharacterId)).AsNoTracking().ToListAsync(); + //var weaponsInUse = await Repository.Get(c => c.CharacterId.Equals(model.CharacterId)).Where(w => w.InUse.Equals(true)).ToListAsync(); + var weaponsInUse = allWeapons.Where(w => w.InUse.Equals(true)).ToList(); + var weapon = Mapper.Map(model); + weapon.Id = allWeapons.Where(w => w.WeaponId.Equals(model.WeaponId)).Select(x => x.Id).FirstOrDefault(); if (weaponsInUse.Count() == 0) { -- 2.20.1 From 42eeb72f1a8f666a72a36ee5957289a2fdcb964a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Wed, 13 Jan 2021 21:17:24 +0100 Subject: [PATCH 8/9] Update 'SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs' --- .../SessionCompanion/Controllers/EquipmentController.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs b/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs index ac6fee8..b9f1e79 100644 --- a/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs +++ b/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs @@ -121,7 +121,11 @@ namespace SessionCompanion.Controllers return new ErrorResponse() { StatusCode = 500, Message = e.Message }; } } - + /// + /// Metoda zmienia Weapon do danej postaci + /// + /// + /// [HttpPut("changeWeapon")] public async Task> ChangeCharacterWeapon(CharacterWeaponViewModel characterWeaponViewModel) { -- 2.20.1 From d26d9278a31383017b9c527467bb8318bcd19f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Wed, 13 Jan 2021 21:50:21 +0100 Subject: [PATCH 9/9] SES-148 Implement feedback --- .../Services/CharacterArmorService.cs | 6 +++--- .../Services/CharacterWeaponService.cs | 1 - .../Controllers/EquipmentController.cs | 20 +++++++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs b/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs index 89744cc..9413e2f 100644 --- a/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs +++ b/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs @@ -41,7 +41,7 @@ namespace SessionCompanion.Services.Services } if (armorToUse is null) - return new ErrorResponse() { StatusCode = 204, Message = "No weapon to change to" }; + return new ErrorResponse() { StatusCode = 204, Message = "No armor to change to" }; if (armorInUse is null) { @@ -50,7 +50,7 @@ namespace SessionCompanion.Services.Services { await Repository.Update(armorToUse); await Repository.Save(); - return new SuccessResponse("Character weapon updated") { SuccessCode = 200 }; + return new SuccessResponse("Character armor updated") { SuccessCode = 200 }; } catch (Exception e) { @@ -65,7 +65,7 @@ namespace SessionCompanion.Services.Services await Repository.Update(armorInUse); await Repository.Update(armorToUse); await Repository.Save(); - return new SuccessResponse("Character weapon updated") { SuccessCode = 204 }; + return new SuccessResponse("Character armor updated") { SuccessCode = 204 }; } catch (Exception e) { diff --git a/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs b/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs index 01addda..e003791 100644 --- a/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs +++ b/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs @@ -37,7 +37,6 @@ namespace SessionCompanion.Services.Services { // Dodaj optional rozbro postac var allWeapons = await Repository.Get(c => c.CharacterId.Equals(model.CharacterId)).AsNoTracking().ToListAsync(); - //var weaponsInUse = await Repository.Get(c => c.CharacterId.Equals(model.CharacterId)).Where(w => w.InUse.Equals(true)).ToListAsync(); var weaponsInUse = allWeapons.Where(w => w.InUse.Equals(true)).ToList(); var weapon = Mapper.Map(model); diff --git a/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs b/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs index ac6fee8..1331603 100644 --- a/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs +++ b/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs @@ -66,11 +66,11 @@ namespace SessionCompanion.Controllers } /// - /// Metoda zmienia uzywany armor danej postaci + /// Metoda zmienia uzywaną zbroję danej postaci na taki jaki jest wybrany /// - /// - /// - /// + /// Id postaci + /// Id nowej zbroi + /// SuccessResponse/ErrorResponse [HttpPut("changeArmor")] public async Task> ChangeCharacterArmor(int characterId, int newArmorId) { @@ -79,10 +79,10 @@ namespace SessionCompanion.Controllers } /// - /// Metoda dodaje Armor do danej postaci + /// Metoda dodaje nową zbroje do danej postaci /// - /// - /// + /// View model z odpowiednimi parameterami + /// SuccessResponse/ErrorResponse [HttpPut("addArmor")] public async Task> AddCharacterArmor(CharacterArmorViewModel characterArmorViewModel) { @@ -101,10 +101,10 @@ namespace SessionCompanion.Controllers } /// - /// Metoda dodaje Weapon do danej postaci + /// Metoda dodaje broń do danej postaci /// - /// - /// + /// View model z odpowiednimi parameterami + /// SuccessResponse/ErrorResponse [HttpPut("addWeapon")] public async Task> AddCharacterWeapon(CharacterWeaponViewModel characterWeaponViewModel) { -- 2.20.1