106 lines
2.2 KiB
C#
106 lines
2.2 KiB
C#
using CanteenContracts.BindingModels;
|
||
using CanteenContracts.BusinessLogicsContracts;
|
||
using CanteenContracts.SearchModel;
|
||
using CanteenContracts.ViewModels;
|
||
using CanteenDataModels.Enums;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
|
||
namespace CanteenRestAPI.Controllers
|
||
{
|
||
[Route("api/[controller]/[action]")]
|
||
[ApiController]
|
||
public class CookController : Controller
|
||
{
|
||
private readonly ILogger _logger;
|
||
private readonly IOrderLogic _order;
|
||
private readonly ICookLogic _logic;
|
||
public CookController(IOrderLogic order, ICookLogic logic, ILogger<CookController> logger)
|
||
{
|
||
_logger = logger;
|
||
_order = order;
|
||
_logic = logic;
|
||
}
|
||
|
||
[HttpGet]
|
||
public CookViewModel? Login(string login, string password)
|
||
{
|
||
try
|
||
{
|
||
return _logic.ReadElement(new CookSearchModel
|
||
{
|
||
Email = login,
|
||
Password = password
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка авторизации сотрудника");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
public List<OrderViewModel>? GetNewOrders()
|
||
{
|
||
try
|
||
{
|
||
return _order.ReadList(new OrderSearchModel
|
||
{
|
||
OrderStatuses = new() { OrderStatus.Принят },
|
||
PaymentStatuses = new() { PaymentStatus.Неоплачен }
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Ошибка получения новых заказов");
|
||
throw;
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
public OrderViewModel? GetCookOrder(int cookId)
|
||
{
|
||
try
|
||
{
|
||
return _order.ReadElement(new OrderSearchModel
|
||
{
|
||
CookId = cookId
|
||
});
|
||
}
|
||
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;
|
||
}
|
||
}
|
||
}
|
||
}
|