Pibd-22_Presnyakova.V.V_Jew.../JewelryStoreRestApi/Controllers/ImplementerController.cs

107 lines
3.0 KiB
C#
Raw Normal View History

2023-04-17 18:05:56 +04:00
using JewelryStoreContracts.BindingModels;
using JewelryStoreContracts.BusinessLogicsContracts;
using JewelryStoreContracts.SearchModels;
using JewelryStoreContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
2023-04-17 16:50:56 +04:00
namespace JewelryStoreRestApi.Controllers
{
2023-04-17 18:05:56 +04:00
[Route("api/[controller]/[action]")]
[ApiController]
2023-04-17 16:50:56 +04:00
public class ImplementerController : Controller
{
2023-04-17 18:05:56 +04:00
private readonly ILogger _logger;
private readonly IOrderLogic _order;
private readonly IImplementerLogic _logic;
public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger<ImplementerController> 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<OrderViewModel>? 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
{
2023-04-17 23:38:44 +04:00
ImplementerId = implementerId
2023-04-17 18:05:56 +04:00
});
}
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)
2023-04-17 16:50:56 +04:00
{
2023-04-17 18:05:56 +04:00
try
{
_order.FinishOrder(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id);
throw;
}
2023-04-17 16:50:56 +04:00
}
}
}