using DocumentFormat.OpenXml.Office2010.Excel; using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicContracts; using AutomobilePlantContracts.SearchModels; using AutomobilePlantContracts.ViewModels; using Microsoft.AspNetCore.Mvc; namespace AutomobilePlantRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class MainController : Controller { private readonly ILogger _logger; private readonly IOrderLogic _order; private readonly ICarLogic _car; public MainController(ILogger logger, IOrderLogic order, ICarLogic car) { _logger = logger; _order = order; _car = car; } [HttpGet] public List? GetCarList() { try { return _car.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка авто"); throw; } } [HttpGet] public CarViewModel? GetCar(int carId) { try { return _car.ReadElement(new CarSearchModel { Id = carId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения авто по id={Id}", carId); 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; } } } }