From 9670a684932f3995ba56fa2eab6cc61b17c691d4 Mon Sep 17 00:00:00 2001 From: shadowik Date: Sun, 14 May 2023 09:29:11 +0400 Subject: [PATCH] . --- .../Controllers/CardController.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CardController.cs diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CardController.cs b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CardController.cs new file mode 100644 index 0000000..d2e583a --- /dev/null +++ b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CardController.cs @@ -0,0 +1,54 @@ +using BankYouBankruptContracts.BindingModels; +using BankYouBankruptContracts.BusinessLogicsContracts; +using BankYouBankruptContracts.SearchModels; +using BankYouBankruptContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; +using System.Linq.Expressions; +using System.Net; + +namespace BankYouBankruptRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class CardController : Controller + { + private readonly ILogger _logger; + + private readonly ICardLogic _cardLogic; + + public CardController(ICardLogic cardLogic, ILogger logger) + { + _logger = logger; + _cardLogic = cardLogic; + } + + [HttpGet] + public List? GetUsersCardsList(int id) + { + try + { + return _cardLogic.ReadList(new CardSearchModel { Id = id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения карт"); + throw; + } + + } + + [HttpPost] + public void CreateCard(CardBindingModel model) { + try + { + _cardLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания карты"); + Response.StatusCode = (int)HttpStatusCode.NotAcceptable; + } + + } + } +}