using ComputerShopContracts.BindingModels; using ComputerShopContracts.BusinessLogicContracts; using ComputerShopContracts.SearchModels; using ComputerShopContracts.ViewModels; using Microsoft.AspNetCore.Mvc; namespace ComputerShopRestApi.Controllers { [Route("api/[controller]/[action]")] [ApiController] public class AssemblyController : Controller { private readonly ILogger _logger; private readonly IAssemblyLogic _assemblyLogic; private readonly IReportGuarantorLogic _reportGuarantorLogic; public AssemblyController(IAssemblyLogic Logic, ILogger Logger, IReportGuarantorLogic reportGuarantorLogic) { _logger = Logger; _assemblyLogic = Logic; _reportGuarantorLogic = reportGuarantorLogic; } [HttpGet] public AssemblyViewModel? GetAssembly(int Id) { try { return _assemblyLogic.ReadElement(new AssemblySearchModel { Id = Id }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения сборки"); throw; } } [HttpGet] public List? GetAssemblies(int? UserId) { // Implementer should be able to get all assemblies for Request binding if (UserId == null) { try { return _assemblyLogic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка всех сборок"); throw; } } try { return _assemblyLogic.ReadList(new AssemblySearchModel { UserId = UserId }); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка сборок пользователя с Id = {Id}", UserId); throw; } } [HttpPost] public void CreateAssembly(AssemblyBindingModel Model) { try { _assemblyLogic.Create(Model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания сборки"); throw; } } [HttpPost] public void UpdateAssembly(AssemblyBindingModel Model) { try { _assemblyLogic.Update(Model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка обновления сборки"); throw; } } [HttpPost] public void DeleteAssembly(AssemblyBindingModel Model) { try { _assemblyLogic.Delete(Model); } catch (Exception ex) { _logger.LogError(ex, "Ошибка удаления сборки"); throw; } } } }