107 lines
2.8 KiB
C#
107 lines
2.8 KiB
C#
|
using FoodOrdersContracts.BindingModels;
|
|||
|
using FoodOrdersContracts.BusinessLogicsContracts;
|
|||
|
using FoodOrdersContracts.SearchModels;
|
|||
|
using FoodOrdersContracts.ViewModels;
|
|||
|
using FoodOrdersDataModels.Enums;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
|||
|
namespace AbstractShopRestApi.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<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, "Employee authorization error");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public List<OrderViewModel>? GetNewOrders()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _order.ReadList(new OrderSearchModel
|
|||
|
{
|
|||
|
Status = OrderStatus.Принят
|
|||
|
});
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Error receiving new orders");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet]
|
|||
|
public OrderViewModel? GetImplementerOrder(int implementerId)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
return _order.ReadElement(new OrderSearchModel
|
|||
|
{
|
|||
|
ImplementerId = implementerId
|
|||
|
});
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Error of receiving the current order of an implementer");
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void TakeOrderInWork(OrderBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_order.TakeOrderInWork(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Taking order №{Id} in work error", model.Id);
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost]
|
|||
|
public void FinishOrder(OrderBindingModel model)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_order.FinishOrder(model);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_logger.LogError(ex, "Finishing order №{Id} error", model.Id);
|
|||
|
throw;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|