PIbd-21_MasenkinMS_Aircraft.../AircraftPlant/AircraftPlantRestApi/Controllers/ImplementerController.cs

149 lines
4.6 KiB
C#
Raw Permalink Normal View History

2024-04-20 22:35:38 +04:00
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.BusinessLogicsContracts;
using AircraftPlantContracts.SearchModels;
using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Enums;
using Microsoft.AspNetCore.Mvc;
namespace AircraftPlantRestApi.Controllers
{
/// <summary>
/// Контроллер для работы с исполнителями
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class ImplementerController : Controller
{
/// <summary>
/// Логгер
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Бизнес-логика для заказов
/// </summary>
private readonly IOrderLogic _orderLogic;
/// <summary>
/// Бизнес-логика для исполнителей
/// </summary>
private readonly IImplementerLogic _implementerLogic;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="orderLogic"></param>
/// <param name="implementerLogic"></param>
/// <param name="logger"></param>
public ImplementerController(IOrderLogic orderLogic, IImplementerLogic implementerLogic, ILogger<ImplementerController> logger)
{
_logger = logger;
_orderLogic = orderLogic;
_implementerLogic = implementerLogic;
}
/// <summary>
/// Авторизация исполнителя
/// </summary>
/// <param name="login"></param>
/// <param name="password"></param>
/// <returns></returns>
[HttpGet]
public ImplementerViewModel? Login(string login, string password)
{
try
{
return _implementerLogic.ReadElement(new ImplementerSearchModel
{
ImplementerFIO = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа сотрудника");
throw;
}
}
/// <summary>
/// Получение новых заказов
/// </summary>
/// <returns></returns>
[HttpGet]
public List<OrderViewModel>? GetNewOrders()
{
try
{
return _orderLogic.ReadList(new OrderSearchModel
{
Status = OrderStatus.Принят
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения новых заказов");
throw;
}
}
/// <summary>
/// Получение текущего заказа исполнителя
/// </summary>
/// <param name="implementerId"></param>
/// <returns></returns>
[HttpGet]
public OrderViewModel? GetImplementerOrder(int implementerId)
{
try
{
return _orderLogic.ReadElement(new OrderSearchModel
{
ImplementerId = implementerId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения текущего заказа исполнителя");
throw;
}
}
/// <summary>
/// Смена статуса заказа (Выполняется)
/// </summary>
/// <param name="model"></param>
[HttpPost]
public void TakeOrderInWork(OrderBindingModel model)
{
try
{
_orderLogic.TakeOrderInWork(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id);
throw;
}
}
/// <summary>
/// Смена статуса заказа (Выдан)
/// </summary>
/// <param name="model"></param>
[HttpPost]
public void FinishOrder(OrderBindingModel model)
{
try
{
_orderLogic.FinishOrder(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id);
throw;
}
}
}
}