From d741deca2777845fed294ffae2b5fe3bc77d3c8f Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 3 May 2024 23:34:34 +0400 Subject: [PATCH] =?UTF-8?q?+=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB?= =?UTF-8?q?=D0=BB=D0=B5=D1=80,=20=D1=8F=20=D1=85=D0=BE=D1=87=D1=83=20?= =?UTF-8?q?=D1=81=D0=BF=D0=B0=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogicsContracts/IOrderLogic.cs | 3 +- .../SearchModels/OrderSearchModel.cs | 7 +- .../Controllers/ImplementerController.cs | 103 ++++++++++++++++++ 3 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 Confectionery/ConfectioneryRestApi/Controllers/ImplementerController.cs diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs index fc1f506..514ce78 100644 --- a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -16,5 +16,6 @@ namespace ConfectioneryContracts.BusinessLogicsContracts bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); - } + OrderViewModel? ReadElement(OrderSearchModel model); + } } diff --git a/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs index d636d99..12b9e78 100644 --- a/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs +++ b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using ConfectioneryDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,7 +11,9 @@ namespace ConfectioneryContracts.SearchModels { public int? Id { get; set; } public int? ClientId { get; set; } - public DateTime? DateFrom { get; set; } + public OrderStatus? Status { get; set; } + public int? ImplementerId { get; set; } + public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } } } diff --git a/Confectionery/ConfectioneryRestApi/Controllers/ImplementerController.cs b/Confectionery/ConfectioneryRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..43944b7 --- /dev/null +++ b/Confectionery/ConfectioneryRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,103 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; +using DocumentFormat.OpenXml.Office2010.Excel; +using Microsoft.AspNetCore.Mvc; + +namespace ConfectioneryRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IImplementerLogic _logic; + public ImplementerController(IOrderLogic order, IImplementerLogic logic, + ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + + + throw; + } + } + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id); + throw; + } + } + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с№{ Id}", model.Id); + throw; + } + } + } +}