using DocumentFormat.OpenXml.Office2010.Excel; using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.ViewModels; using Microsoft.AspNetCore.Mvc; namespace JewelryStoreRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class MainController : Controller { private readonly ILogger _logger; private readonly IOrderLogic _order; private readonly IJewelLogic _jewel; public MainController(ILogger logger, IOrderLogic order, IJewelLogic jewel) { _logger = logger; _order = order; _jewel = jewel; } [HttpGet] public List? GetJewelList() { try { return _jewel.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка драгоценностей"); throw; } } [HttpGet] public JewelViewModel? GetJewel(int jewelId) { try { return _jewel.ReadElement(new JewelSearchModel { Id = jewelId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения драгоценности по id={Id}", jewelId); 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; } } } }