From 0c29cb0554793110c15f6d36ddc573eb71747327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Thu, 7 Jan 2021 16:45:54 +0100 Subject: [PATCH 1/2] SES-130 Create Armor Controller and Endpoint to return all armor --- .../Controllers/ArmorController.cs | 28 +++++++++++++++++++ .../SessionCompanion/SessionCompanion.csproj | 4 --- .../SessionCompanion/SessionCompanion.xml | 6 ++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 SessionCompanion/SessionCompanion/Controllers/ArmorController.cs diff --git a/SessionCompanion/SessionCompanion/Controllers/ArmorController.cs b/SessionCompanion/SessionCompanion/Controllers/ArmorController.cs new file mode 100644 index 0000000..41c6048 --- /dev/null +++ b/SessionCompanion/SessionCompanion/Controllers/ArmorController.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Mvc; +using SessionCompanion.Services.Interfaces; +using SessionCompanion.ViewModels.ArmorViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SessionCompanion.Controllers +{ + [Route("api/armor")] + [ApiController] + public class ArmorController : Controller + { + private readonly IArmorService _service; + public ArmorController(IArmorService service) => _service = service; + + /// + /// Metoda zwraca wszystkie dostępne pancerze + /// + /// Lista wszystkich pancerzy w bazie danych + [HttpGet("getAllArmor")] + public async Task> GetArmors() + { + return _service.Get().ToList(); + } + } +} diff --git a/SessionCompanion/SessionCompanion/SessionCompanion.csproj b/SessionCompanion/SessionCompanion/SessionCompanion.csproj index c455a8f..f0f585f 100644 --- a/SessionCompanion/SessionCompanion/SessionCompanion.csproj +++ b/SessionCompanion/SessionCompanion/SessionCompanion.csproj @@ -36,10 +36,6 @@ - - - - diff --git a/SessionCompanion/SessionCompanion/SessionCompanion.xml b/SessionCompanion/SessionCompanion/SessionCompanion.xml index b96a03b..1c7e742 100644 --- a/SessionCompanion/SessionCompanion/SessionCompanion.xml +++ b/SessionCompanion/SessionCompanion/SessionCompanion.xml @@ -4,6 +4,12 @@ SessionCompanion + + + Metoda zwraca wszystkie dostępne pancerze + + Lista wszystkich pancerzy w bazie danych + Metoda zwraca postać ze wskazanym identyfikatorem -- 2.20.1 From ab0aae1cdb44a3d36af93580dc73e35f47d96c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20G=C3=B3rzy=C5=84ski?= Date: Fri, 8 Jan 2021 17:45:02 +0100 Subject: [PATCH 2/2] SES-130 Add Error Reponse --- .../Controllers/ArmorController.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/SessionCompanion/SessionCompanion/Controllers/ArmorController.cs b/SessionCompanion/SessionCompanion/Controllers/ArmorController.cs index 41c6048..c690275 100644 --- a/SessionCompanion/SessionCompanion/Controllers/ArmorController.cs +++ b/SessionCompanion/SessionCompanion/Controllers/ArmorController.cs @@ -1,5 +1,7 @@ using Microsoft.AspNetCore.Mvc; +using SessionCompanion.Extensions.EitherType; using SessionCompanion.Services.Interfaces; +using SessionCompanion.ViewModels.ApiResponses; using SessionCompanion.ViewModels.ArmorViewModels; using System; using System.Collections.Generic; @@ -20,9 +22,21 @@ namespace SessionCompanion.Controllers /// /// Lista wszystkich pancerzy w bazie danych [HttpGet("getAllArmor")] - public async Task> GetArmors() + public async Task, ErrorResponse>> GetArmors() { - return _service.Get().ToList(); + try + { + var armors = _service.Get().ToList(); + return armors; + } + catch (Exception e) + { + return new ErrorResponse() + { + StatusCode = 204, + Message = e.Message + }; + } } } } -- 2.20.1