From 7fb925523d5f492c4b5990c3ae3806cf5dfc44af Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 14 May 2023 13:30:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB?= =?UTF-8?q?=D0=BB=D0=B5=D1=80=20=D1=81=D1=87=D1=91=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/CashierLogic.cs | 2 +- .../Controllers/AccountController.cs | 91 +++++++++++++++++++ .../Controllers/CashierController.cs | 4 +- .../BankYouBankruptRestAPI/Program.cs | 2 +- 4 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 BankYouBankrupt/BankYouBankruptRestAPI/Controllers/AccountController.cs diff --git a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashierLogic.cs b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashierLogic.cs index d7e810c..2ebe3d1 100644 --- a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashierLogic.cs +++ b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/CashierLogic.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace BankYouBankruptBusinessLogic.BusinessLogics { - public class CashierLogic : ICashierLogic + public class CashierLogic : IAccountLogic { private readonly ILogger _logger; diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/AccountController.cs b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/AccountController.cs new file mode 100644 index 0000000..83c9fcc --- /dev/null +++ b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/AccountController.cs @@ -0,0 +1,91 @@ +using BankYouBankruptContracts.BindingModels; +using BankYouBankruptContracts.BusinessLogicsContracts; +using BankYouBankruptContracts.SearchModels; +using BankYouBankruptContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace BankYouBankruptRestApi.Controllers +{ + //указание у контроллера, что Route будет строиться не только по наванию контроллера, но и по названию метода (так как у нас два Post-метода) + [Route("api/[controller]/[action]")] + [ApiController] + public class AccountController : Controller + { + private readonly ILogger _logger; + + private readonly IAccountLogic _accountLogic; + + public AccountController(IAccountLogic accountLogic, ILogger logger) + { + _logger = logger; + _accountLogic = accountLogic; + } + + [HttpGet] + public AccountViewModel? Login(string accountNumber, string passwordAccount) + { + try + { + //попытка найти запись по переданным номеру и паролю счёта + return _accountLogic.ReadElement(new AccountSearchModel + { + AccountNumber = accountNumber, + PasswordAccount = passwordAccount + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + + [HttpPost] + public void Register(AccountBindingModel model) + { + try + { + //создание счёта + _accountLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + + [HttpPost] + public void UpdateData(AccountBindingModel model) + { + try + { + //изменение счёта + _accountLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + + [HttpGet] + public List? SearchAllAccounts(int cashierId) + { + try + { + //попытка найти запись по переданным номеру и паролю счёта + return _accountLogic.ReadList(new AccountSearchModel + { + CashierId = cashierId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + } +} diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CashierController.cs b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CashierController.cs index 9fb86de..b86f84e 100644 --- a/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CashierController.cs +++ b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/CashierController.cs @@ -13,9 +13,9 @@ namespace BankYouBankruptRestApi.Controllers { private readonly ILogger _logger; - private readonly ICashierLogic _cashierLogic; + private readonly IAccountLogic _cashierLogic; - public CashierController(ICashierLogic cashierLogic, ILogger logger) + public CashierController(IAccountLogic cashierLogic, ILogger logger) { _logger = logger; _cashierLogic = cashierLogic; diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs b/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs index c00d53b..2247491 100644 --- a/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs +++ b/BankYouBankrupt/BankYouBankruptRestAPI/Program.cs @@ -21,7 +21,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient();