using ComputerShopContracts.BindingModels; using ComputerShopContracts.BusinessLogicContracts; using ComputerShopContracts.SearchModels; using ComputerShopContracts.ViewModels; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace ComputerShopRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class SupplyController : Controller { private readonly ILogger _logger; private readonly ISupplyLogic _supply; private readonly IOrderLogic _order; private readonly IEquipmentReceivingLogic _equipmentReceiving; public SupplyController(ILogger logger, ISupplyLogic supply, IOrderLogic order, IEquipmentReceivingLogic equipmentReceiving) { _logger = logger; _supply = supply; _order = order; _equipmentReceiving = equipmentReceiving; } [HttpGet] public List? GetReceivingList() { try { return _equipmentReceiving.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка компонентов"); throw; } } [HttpGet] public List? GetSupplyList(int componentid) { try { return _supply.ReadList(new SupplySearchModel { ComponentId = componentid }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка сборок"); throw; } } [HttpGet] public List? GetOrderList() { try { return _order.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка заказов"); throw; } } [HttpPost] public void CreateAssembly(SupplyBindingModel model) { try { _supply.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания поставки"); throw; } } [HttpPost] public void DeleteSupply(SupplyBindingModel model) { try { _supply.Delete(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления поставки"); throw; } } [HttpPost] public void AddOrderToSupply(Tuple model) { try { _supply.AddOrder(model.Item1, model.Item2); } catch (Exception ex) { _logger.LogError(ex, "Ошибка."); throw; } } [HttpPost] public void EditOrder(OrderBindingModel model) { try { _order.Update(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления заказа"); throw; } } } }