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();