ISEbd-21_KashtanovD.A.FishF.../FishFactory/FishFactoryRestApi/Controllers/MainController.cs
2024-04-26 00:17:50 +04:00

85 lines
2.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DocumentFormat.OpenXml.Office2010.Excel;
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.BusinessLogicsContracts;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace AbstractShopRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class MainController : Controller
{
private readonly ILogger _logger;
private readonly IOrderLogic _order;
private readonly ICannedLogic _canned;
public MainController(ILogger<MainController> logger, IOrderLogic order,
ICannedLogic canned)
{
_logger = logger;
_order = order;
_canned = canned;
}
[HttpGet]
public List<CannedViewModel>? GetCannedList()
{
try
{
return _canned.ReadList(null);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка продуктов");
throw;
}
}
[HttpGet]
public CannedViewModel? GetCanned(int cannedId)
{
try
{
return _canned.ReadElement(new CannedSearchModel
{
Id =
cannedId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения продукта по id={Id}",
cannedId);
throw;
}
}
[HttpGet]
public List<OrderViewModel>? GetOrders(int clientId)
{
try
{
return _order.ReadList(new OrderSearchModel
{
ClientId = clientId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка заказов клиентаid ={ Id}", clientId);
throw;
}
}
[HttpPost]
public void CreateOrder(OrderBindingModel model)
{
try
{
_order.CreateOrder(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
throw;
}
}
}
}