From abb484abf17ed560fb1cd49e5a8c05fafb02490d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20G=C3=B3reczny?= Date: Tue, 12 Jan 2021 12:46:50 +0100 Subject: [PATCH] SES-142 Added endpoints for character equipment --- .../Intefraces/ICharacterArmorService.cs | 1 + .../ICharacterOtherEquipmentService.cs | 1 + .../Intefraces/ICharacterWeaponService.cs | 4 ++ .../Services/CharacterArmorService.cs | 14 ++++ .../CharacterOtherEquipmentService.cs | 16 +++++ .../Services/CharacterWeaponService.cs | 19 +++++ .../Controllers/EquipmentController.cs | 69 +++++++++++++++++++ 7 files changed, 124 insertions(+) create mode 100644 SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs diff --git a/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterArmorService.cs b/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterArmorService.cs index 08f0382..e380b04 100644 --- a/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterArmorService.cs +++ b/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterArmorService.cs @@ -12,5 +12,6 @@ namespace SessionCompanion.Services.Interfaces public interface ICharacterArmorService : IServiceBase { + Task> GetCharacterArmorsTaskList(int characterId); } } diff --git a/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterOtherEquipmentService.cs b/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterOtherEquipmentService.cs index ec20aca..e9e8a90 100644 --- a/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterOtherEquipmentService.cs +++ b/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterOtherEquipmentService.cs @@ -12,5 +12,6 @@ namespace SessionCompanion.Services.Interfaces public interface ICharacterOtherEquipmentService : IServiceBase { + Task> GetCharacterOtherEquipmentList(int characterId); } } diff --git a/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterWeaponService.cs b/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterWeaponService.cs index 3ac386e..8206eb9 100644 --- a/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterWeaponService.cs +++ b/SessionCompanion/SessionCompanion.Services/Intefraces/ICharacterWeaponService.cs @@ -4,7 +4,11 @@ using SessionCompanion.ViewModels.CharacterWeaponViewModels; namespace SessionCompanion.Services.Interfaces { + using System.Collections.Generic; + using System.Threading.Tasks; + public interface ICharacterWeaponService : IServiceBase { + Task> GetCharacterWeaponsList(int characterId); } } diff --git a/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs b/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs index 8b417dd..b3d64e0 100644 --- a/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs +++ b/SessionCompanion/SessionCompanion.Services/Services/CharacterArmorService.cs @@ -16,10 +16,24 @@ namespace SessionCompanion.Services.Services using SessionCompanion.Services.Base; using SessionCompanion.Services.Interfaces; using SessionCompanion.ViewModels.CharacterArmorViewModels; + using SessionCompanion.ViewModels.CharacterOtherEquipmentViewModels; public class CharacterArmorService : ServiceBase, ICharacterArmorService { public CharacterArmorService(IMapper mapper, IRepository repository) : base(mapper, repository) { } + + /// + /// Metoda pobiera listę pancerzy konkretnej postaci + /// + /// Id postaci + /// Lista pancerzy posiadanych przez postać + public async Task> GetCharacterArmorsTaskList(int characterId) + { + var characterWeapons = await Repository.Get().Where(a => a.CharacterId.Equals(characterId)).Include(a => a.Armor).ToListAsync(); + + var result = Mapper.Map>(characterWeapons); + return result; + } } } diff --git a/SessionCompanion/SessionCompanion.Services/Services/CharacterOtherEquipmentService.cs b/SessionCompanion/SessionCompanion.Services/Services/CharacterOtherEquipmentService.cs index 1d80427..83187dc 100644 --- a/SessionCompanion/SessionCompanion.Services/Services/CharacterOtherEquipmentService.cs +++ b/SessionCompanion/SessionCompanion.Services/Services/CharacterOtherEquipmentService.cs @@ -1,7 +1,11 @@ namespace SessionCompanion.Services.Services { + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; using AutoMapper; + using Microsoft.EntityFrameworkCore; using SessionCompanion.Database.Repositories.Base; using SessionCompanion.Database.Tables; using SessionCompanion.Services.Base; @@ -13,5 +17,17 @@ public CharacterOtherEquipmentService(IMapper mapper, IRepository repository) : base(mapper, repository) { } + /// + /// Metoda pobiera listę pozostałego ekwipunku konkretnej postaci + /// + /// Id postaci + /// Lista pozostałego ekwpinuku posiadanego przez postać + public async Task> GetCharacterOtherEquipmentList(int characterId) + { + var characterWeapons = await Repository.Get().Where(a => a.CharacterId.Equals(characterId)).Include(a => a.OtherEquipment).ToListAsync(); + + var result = Mapper.Map>(characterWeapons); + return result; + } } } diff --git a/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs b/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs index 3dae1ac..2e54b32 100644 --- a/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs +++ b/SessionCompanion/SessionCompanion.Services/Services/CharacterWeaponService.cs @@ -7,9 +7,28 @@ using SessionCompanion.ViewModels.CharacterWeaponViewModels; namespace SessionCompanion.Services.Services { + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + + using Microsoft.EntityFrameworkCore; + public class CharacterWeaponService : ServiceBase, ICharacterWeaponService { public CharacterWeaponService(IMapper mapper, IRepository repository) : base(mapper, repository) { } + + /// + /// Metoda pobiera listę broni konkretnej postaci + /// + /// Id postaci + /// Lista broni posiadanych przez postać + public async Task> GetCharacterWeaponsList(int characterId) + { + var characterWeapons = await Repository.Get().Where(w => w.CharacterId.Equals(characterId)).Include(w => w.Weapon).ToListAsync(); + + var result = Mapper.Map>(characterWeapons); + return result; + } } } diff --git a/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs b/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs new file mode 100644 index 0000000..ef1fd92 --- /dev/null +++ b/SessionCompanion/SessionCompanion/Controllers/EquipmentController.cs @@ -0,0 +1,69 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SessionCompanion.Controllers +{ + using SessionCompanion.Extensions.EitherType; + using SessionCompanion.Services.Interfaces; + using SessionCompanion.ViewModels.ApiResponses; + using SessionCompanion.ViewModels.CharacterArmorViewModels; + using SessionCompanion.ViewModels.CharacterOtherEquipmentViewModels; + using SessionCompanion.ViewModels.CharacterWeaponViewModels; + + [Route("api/character/equipment")] + [ApiController] + public class EquipmentController : Controller + { + private readonly ICharacterArmorService _characterArmorServic; + + private readonly ICharacterOtherEquipmentService _characterOtherEquipmentService; + + private readonly ICharacterWeaponService _characterWeaponService; + + public EquipmentController(ICharacterArmorService characterArmorService, + ICharacterOtherEquipmentService characterOtherEquipmentService, + ICharacterWeaponService characterWeaponService) + { + this._characterArmorServic = characterArmorService; + this._characterOtherEquipmentService = characterOtherEquipmentService; + this._characterWeaponService = characterWeaponService; + } + + /// + /// Zwraca listę pozostałego ekwipunku dla danej postaci + /// + /// Id postaci + /// Lista pozostałego ekwipunku lub błąd + [HttpGet("getOtherEquipment")] + public async Task, ErrorResponse>> GetCharacterOtherEquipment(int characterId) + { + return await this._characterOtherEquipmentService.GetCharacterOtherEquipmentList(characterId); + } + + /// + /// Zwraca listę pancerzy posiadanych przez daną postać + /// + /// Id postaci + /// Lista pozostałego ekwipunku lub błąd + [HttpGet("getArmors")] + public async Task, ErrorResponse>> GetCharacterArmors(int characterId) + { + return await this._characterArmorServic.GetCharacterArmorsTaskList(characterId); + } + + /// + /// Zwraca listę broni posiadanej przez daną postać + /// + /// Id postaci + /// Lista broni lub błąd + [HttpGet("getWeapons")] + public async Task, ErrorResponse>> GetCharacterWeapons(int characterId) + { + return await this._characterWeaponService.GetCharacterWeaponsList(characterId); + } + + } +} -- 2.20.1