using BankContracts.BindingModels.Cashier; using BankContracts.BusinessLogicsContracts.Cashier; using BankContracts.BusinessLogicsContracts.Client; using BankContracts.SearchModels.Cashier; using BankContracts.SearchModels.Client; using BankContracts.ViewModels; using BankContracts.ViewModels.Cashier.ViewModels; using BankContracts.ViewModels.Client.ViewModels; using Microsoft.AspNetCore.Mvc; namespace BankRestAPI.Controllers { // Route будет строиться по наванию контроллера и по названию метода (два Post-метода) [Route("api/[controller]/[action]")] [ApiController] public class AccountController : Controller { private readonly ILogger _logger; private readonly IAccountLogic _accountLogic; private readonly IDebitingLogic _debitingLogic; private readonly ICreditingLogic _creditingLogic; private readonly ICashWithdrawalLogic _cashwithdrawalLogic; private readonly IMoneyTransferLogic _moneyTransferLogic; // Конструктор public AccountController(ILogger logger, IAccountLogic accountLogic, IDebitingLogic debitingLogic, ICreditingLogic creditingLogic, ICashWithdrawalLogic cashWithdrawalLogic, IMoneyTransferLogic moneyTransferLogic) { _logger = logger; _accountLogic = accountLogic; _debitingLogic = debitingLogic; _creditingLogic = creditingLogic; _cashwithdrawalLogic = cashWithdrawalLogic; _moneyTransferLogic = moneyTransferLogic; } [HttpGet] public AccountViewModel? Login(string accountNumber, string passwordAccount) { try { // Попытка найти счёт (запись) по переданным номеру и паролю счёта return _accountLogic.ReadElement(new AccountSearchModel { AccountNumber = accountNumber, }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка входа в систему"); throw; } } [HttpGet] public AccountViewModel? GetAccount(int accountId) { try { // Попробуем получить счёт return _accountLogic.ReadElement(new AccountSearchModel { Id = accountId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка входа в систему"); throw; } } [HttpGet] public List? GetAllAccounts() { try { // Попробуем получить все имеющиеся счета return _accountLogic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка входа в систему"); throw; } } [HttpPost] public void RegisterAccount(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? SearchAccounts(int cashierId) { try { // Поиск всех счетов которые сделал конкретный кассир return _accountLogic.ReadList(new AccountSearchModel { CashierId = cashierId }); } catch (Exception ex) { _logger.LogError(ex, "ОШбика входа в систему"); throw; } } [HttpGet] public List? SearchAccountsOfClient(int clientId) { try { // Попытка найти запись по перданным номеру и паролю счета return _accountLogic.ReadList(new AccountSearchModel { ClientId = clientId }); } catch (Exception ex) { _logger.LogError(ex, "ОШибка входа в систему"); throw; } } [HttpGet] public List? FindAllCashWithdrawal() { try { return _cashwithdrawalLogic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка входа в систему"); throw; } } [HttpGet] public List? FindAllMoneyTransfer() { try { return _moneyTransferLogic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка входа в систему"); throw; } } [HttpGet] public CreditingViewModel FindCrediting(int id) { try { // Поиск заявки на зачисление по id return _creditingLogic.ReadElement(new CreditingSearchModel { Id = id }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка входа в систему"); throw; } } [HttpGet] public DebitingViewModel FindDebiting(int id) { try { // Поиск заявки на снятие по id return _debitingLogic.ReadElement(new DebitingSearchModel { Id = id }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка входа в систему"); throw; } } } }