Разделил контроллер

This commit is contained in:
Artyom_Yashin 2024-04-29 15:55:37 +04:00
parent 9903397392
commit f348e49c8b
9 changed files with 398 additions and 310 deletions

View File

@ -16,7 +16,7 @@ namespace BankBusinessLogic.BusinessLogic
{
private readonly ILogger _logger;
private readonly IAccountStorage _accountStorage;
public AccountLogic(ILogger logger, IAccountStorage accountStorage)
public AccountLogic(ILogger<AccountLogic> logger, IAccountStorage accountStorage)
{
_logger = logger;
_accountStorage = accountStorage;

View File

@ -17,7 +17,7 @@ namespace BankBusinessLogic.BusinessLogic
private readonly ILogger _logger;
private readonly IManagerStorage _managerStorage;
public ManagerLogic(ILogger logger, IManagerStorage managerStorage)
public ManagerLogic(ILogger<ManagerLogic> logger, IManagerStorage managerStorage)
{
_logger = logger;
_managerStorage = managerStorage;

View File

@ -16,7 +16,7 @@ namespace BankBusinessLogic.BusinessLogic
{
private readonly ILogger _logger;
private readonly ITransferStorage _transferStorage;
public TransferLogic(ILogger logger, ITransferStorage transferStorage)
public TransferLogic(ILogger<TransferLogic> logger, ITransferStorage transferStorage)
{
_logger = logger;
_transferStorage = transferStorage;

View File

@ -17,7 +17,7 @@ namespace BankBusinessLogic.BusinessLogic
{
private readonly ILogger _logger;
private readonly IWithdrawalStorage _withdrawalStorage;
public WithdrawalLogic(ILogger logger, IWithdrawalStorage withdrawalStorage)
public WithdrawalLogic(ILogger<WithdrawalLogic> logger, IWithdrawalStorage withdrawalStorage)
{
_logger = logger;
_withdrawalStorage = withdrawalStorage;

View File

@ -0,0 +1,94 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class CardController
{
private readonly ILogger _logger;
private readonly ICardLogic _logic;
public CardController(ILogger logger, ICardLogic Card)
{
_logger = logger;
_logic = Card;
}
[HttpGet]
public List<CardViewModel>? GetCardList()
{
try
{
return _logic.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка менеджеров");
throw;
}
}
[HttpGet]
public CardViewModel? GetCard(int CardId)
{
try
{
return _logic.ReadElement(new CardSearchModel
{
Id = CardId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения менеджера по Id={Id}", CardId);
throw;
}
}
[HttpPost]
public void CreateCard(CardBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания менеджера");
throw;
}
}
[HttpPut]
public void UpdateCard(CardBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления менеджера");
throw;
}
}
[HttpDelete]
public void DeleteCard(CardBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления менеджера");
throw;
}
}
}
}

View File

@ -0,0 +1,112 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ClientController : Controller
{
private readonly ILogger _logger;
private readonly IClientLogic _logic;
public ClientController(ILogger logger, IClientLogic client)
{
_logger = logger;
_logic = client;
}
[HttpGet]
public List<ClientViewModel>? GetClientList()
{
try
{
return _logic.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка клиентов");
throw;
}
}
[HttpGet]
public ClientViewModel? GetClient(int ClientId)
{
try
{
return _logic.ReadElement(new ClientSearchModel
{
Id = ClientId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения клиетна по Id={Id}", ClientId);
throw;
}
}
[HttpGet]
public ClientViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new ClientSearchModel
{
Email = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void Register(ClientBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания менеджера");
throw;
}
}
[HttpPut]
public void UpdateClient(ClientBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления менеджера");
throw;
}
}
[HttpDelete]
public void DeleteClient(ClientBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления менеджера");
throw;
}
}
}
}

View File

@ -1,306 +0,0 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System.Diagnostics.Contracts;
namespace BankRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class MainController : Controller
{
private readonly ILogger _logger;
private readonly IClientLogic _client;
private readonly ICardLogic _card;
private readonly IOperationLogic _operation;
private readonly IRequestLogic _request;
public MainController(ILogger<MainController> logger, IClientLogic client, ICardLogic card, IOperationLogic operation, IRequestLogic request)
{
_logger = logger;
_client = client;
_card = card;
_operation = operation;
_request = request;
}
[HttpGet]
public List<ClientViewModel>? GetClientList()
{
try
{
return _client.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка клиентов");
throw;
}
}
[HttpGet]
public ClientViewModel? GetClient(int ClientId)
{
try
{
return _client.ReadElement(new ClientSearchModel
{
Id = ClientId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения клиента по Id={Id}", ClientId);
throw;
}
}
[HttpGet]
public List<CardViewModel>? GetCardList()
{
try
{
return _card.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка карт");
throw;
}
}
[HttpGet]
public CardViewModel? GetCard(int CardId)
{
try
{
return _card.ReadElement(new CardSearchModel
{
Id = CardId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения карты по Id={Id}", CardId);
throw;
}
}
[HttpGet]
public List<OperationViewModel>? getOperationList()
{
try
{
return _operation.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка операций");
throw;
}
}
[HttpGet]
public OperationViewModel? GetOperation(int OperationId)
{
try
{
return _operation.ReadElement(new OperationSearchModel
{
Id = OperationId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения операции по Id={Id}", OperationId);
throw;
}
}
[HttpGet]
public List<RequestViewModel>? GetRequestList()
{
try
{
return _request.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка запросов");
throw;
}
}
[HttpGet]
public RequestViewModel? GetRequest(int RequestId)
{
try
{
return _request.ReadElement(new RequestSearchModel
{
Id = RequestId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения запроса по Id={Id}", RequestId);
throw;
}
}
[HttpPost]
public void CreateClient(ClientBindingModel model)
{
try
{
_client.Create(model);
}
catch(Exception ex)
{
_logger.LogError(ex, "Ошибка создания клиента");
throw;
}
}
[HttpPost]
public void CreateCard(CardBindingModel model)
{
try
{
_card.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания карты");
throw;
}
}
[HttpPost]
public void CreateOperation(OperationBindingModel model)
{
try
{
_operation.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания операции");
throw;
}
}
[HttpPost]
public void CreateRequest(RequestBindingModel model)
{
try
{
_request.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания запроса");
throw;
}
}
[HttpPut]
public void UpdateClient(ClientBindingModel model)
{
try
{
_client.Update(model);
}
catch(Exception ex)
{
_logger.LogError(ex, "Ошибка обновления клиента");
throw;
}
}
[HttpPut]
public void UpdateCard(CardBindingModel model)
{
try
{
_card.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления карты");
throw;
}
}
[HttpPut]
public void UpdateOperation(OperationBindingModel model)
{
try
{
_operation.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления операции");
throw;
}
}
[HttpPut]
public void UpdateRequest(RequestBindingModel model)
{
try
{
_request.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления запроса");
throw;
}
}
[HttpDelete]
public void DeleteClient(ClientBindingModel model)
{
try
{
_client.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления клиента");
throw;
}
}
[HttpDelete]
public void DeleteCard(CardBindingModel model)
{
try
{
_card.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления карты");
throw;
}
}
[HttpDelete]
public void DeleteOperation(OperationBindingModel model)
{
try
{
_operation.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления операции");
throw;
}
}
[HttpDelete]
public void DeleteRequest(RequestBindingModel model)
{
try
{
_request.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления запроса");
throw;
}
}
}
}

View File

@ -0,0 +1,94 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class OperationController
{
private readonly ILogger _logger;
private readonly IOperationLogic _logic;
public OperationController(ILogger logger, IOperationLogic Operation)
{
_logger = logger;
_logic = Operation;
}
[HttpGet]
public List<OperationViewModel>? GetOperationList()
{
try
{
return _logic.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка менеджеров");
throw;
}
}
[HttpGet]
public OperationViewModel? GetOperation(int OperationId)
{
try
{
return _logic.ReadElement(new OperationSearchModel
{
Id = OperationId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения менеджера по Id={Id}", OperationId);
throw;
}
}
[HttpPost]
public void CreateOperation(OperationBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания менеджера");
throw;
}
}
[HttpPut]
public void UpdateOperation(OperationBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления менеджера");
throw;
}
}
[HttpDelete]
public void DeleteOperation(OperationBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления менеджера");
throw;
}
}
}
}

View File

@ -0,0 +1,94 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels;
using BankContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BankRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class RequestController
{
private readonly ILogger _logger;
private readonly IRequestLogic _logic;
public RequestController(ILogger logger, IRequestLogic Request)
{
_logger = logger;
_logic = Request;
}
[HttpGet]
public List<RequestViewModel>? GetRequestList()
{
try
{
return _logic.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка менеджеров");
throw;
}
}
[HttpGet]
public RequestViewModel? GetRequest(int RequestId)
{
try
{
return _logic.ReadElement(new RequestSearchModel
{
Id = RequestId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения менеджера по Id={Id}", RequestId);
throw;
}
}
[HttpPost]
public void CreateRequest(RequestBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания менеджера");
throw;
}
}
[HttpPut]
public void UpdateRequest(RequestBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления менеджера");
throw;
}
}
[HttpDelete]
public void DeleteRequest(RequestBindingModel model)
{
try
{
_logic.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления менеджера");
throw;
}
}
}
}