using Microsoft.AspNetCore.Mvc; using ComputerShopContracts.BindingModels; using ComputerShopContracts.BusinessLogicContracts; using ComputerShopContracts.SearchModels; using ComputerShopContracts.ViewModels; using System.Reflection; namespace ComputerShopRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class ComponentController : Controller { private readonly ILogger _logger; private readonly IComponentLogic _component; public ComponentController(ILogger logger, IComponentLogic component) { _logger = logger; _component = component; } [HttpGet] public List? GetComponentList(int clientId) { try { return _component.ReadList(new ComponentSearchModel { ClientId = clientId, }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка компонентов"); throw; } } [HttpPost] public void CreateComponent(ComponentBindingModel model) { try { _component.Create(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания компонента"); throw; } } [HttpDelete] public void DeleteComponent(ComponentBindingModel model) { try { _component.Delete(model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления компонента"); throw; } } } }