diff --git a/CarpentryWorkshop/CarpentryWorkshopRestApi/CarpentryWorkshopRestApi.csproj b/CarpentryWorkshop/CarpentryWorkshopRestApi/CarpentryWorkshopRestApi.csproj index 6cbf777..1dd3a99 100644 --- a/CarpentryWorkshop/CarpentryWorkshopRestApi/CarpentryWorkshopRestApi.csproj +++ b/CarpentryWorkshop/CarpentryWorkshopRestApi/CarpentryWorkshopRestApi.csproj @@ -11,10 +11,6 @@ - - - - diff --git a/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ClientController.cs b/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ClientController.cs new file mode 100644 index 0000000..a915668 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ClientController.cs @@ -0,0 +1,69 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace CarpentryWorkshopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ClientController : Controller + { + private readonly ILogger _logger; + + private readonly IClientLogic _logic; + + public ClientController(IClientLogic logic, ILogger logger) + { + _logger = logger; + _logic = logic; + } + + [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; + } + } + + [HttpPost] + public void UpdateData(ClientBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/MainController.cs b/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/MainController.cs new file mode 100644 index 0000000..da35b65 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/MainController.cs @@ -0,0 +1,82 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace CarpentryWorkshopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MainController : Controller + { + private readonly ILogger _logger; + + private readonly IOrderLogic _order; + + private readonly IWoodLogic _wood; + + public MainController(ILogger logger, IOrderLogic order, IWoodLogic wood) + { + _logger = logger; + _order = order; + _wood = wood; + } + + [HttpGet] + public List? GetWoodList() + { + try + { + return _wood.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка изделий"); + throw; + } + } + + [HttpGet] + public WoodViewModel? GetWood(int woodId) + { + try + { + return _wood.ReadElement(new WoodSearchModel { Id = woodId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения продукта по id={Id}", woodId); + throw; + } + } + + [HttpGet] + public List? GetOrders(int clientId) + { + try + { + return _order.ReadList(new OrderSearchModel { ClientId = clientId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", clientId); + throw; + } + } + + [HttpPost] + public void CreateOrder(OrderBindingModel model) + { + try + { + _order.CreateOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + throw; + } + } + } +}