2024-05-11 02:30:02 +04:00
|
|
|
|
using FurnitureAssemblyContracts.BindingModels;
|
|
|
|
|
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
|
|
|
|
using FurnitureAssemblyContracts.SearchModels;
|
|
|
|
|
using FurnitureAssemblyContracts.ViewModels;
|
|
|
|
|
using FurnitureAssemblyDataModels.Enums;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace FurnitureAssemblyRestApi.Controllers
|
|
|
|
|
{
|
2024-05-11 23:46:17 +04:00
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ImplementerController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
private readonly IOrderLogic _order;
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
private readonly IImplementerLogic _logic;
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger<ImplementerController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_order = order;
|
|
|
|
|
_logic = logic;
|
|
|
|
|
}
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public ImplementerViewModel? Login(string login, string password)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadElement(new ImplementerSearchModel
|
|
|
|
|
{
|
|
|
|
|
ImplementerFIO = login,
|
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка авторизации сотрудника");
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<OrderViewModel>? GetNewOrders()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _order.ReadList(new OrderSearchModel
|
|
|
|
|
{
|
|
|
|
|
Status = OrderStatus.Принят
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения новых заказов");
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public OrderViewModel? GetImplementerOrder(int implementerId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _order.ReadElement(new OrderSearchModel
|
|
|
|
|
{
|
|
|
|
|
ImplementerId = implementerId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения текущего заказа исполнителя");
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void TakeOrderInWork(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_order.TakeOrderInWork(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id);
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
[HttpPost]
|
|
|
|
|
public void FinishOrder(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_order.FinishOrder(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка отметки о готовности заказа с №{ Id}", model.Id);
|
2024-05-11 02:30:02 +04:00
|
|
|
|
|
2024-05-11 23:46:17 +04:00
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-11 02:30:02 +04:00
|
|
|
|
}
|