using Microsoft.AspNetCore.Mvc; using GarmentFactoryContracts.BindingModels; using GarmentFactoryContracts.BusinessLogicsContracts; using GarmentFactoryContracts.SearchModels; using GarmentFactoryContracts.ViewModels; namespace GarmentFactoryRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class MainController : Controller { private readonly ILogger _logger; private readonly IOrderLogic _order; private readonly ITextileLogic _textile; public MainController(ILogger logger, IOrderLogic order, ITextileLogic textile) { _logger = logger; _order = order; _textile = textile; } [HttpGet] public List? GetTextileList() { try { return _textile.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка продуктов"); throw; } } [HttpGet] public TextileViewModel? GetTextile(int TextileId) { try { return _textile.ReadElement(new TextileSearchModel { Id = TextileId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения продукта по id={Id}", TextileId); throw; } } [HttpGet] public List? 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; } } } }