using BusinessLogic.BusinessLogic; using Contracts.BusinessLogicContracts; using Contracts.SearchModels; using Contracts.ViewModels; using DatabaseImplement.Models; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; namespace RestAPI.Controllers { [Route("[controller]/[action]")] [ApiController] public class MediaFileController : Controller { private readonly IMediaFileLogic _mediaFileLogic; private readonly IProductLogic _productLogic; private readonly ILogger _logger; public MediaFileController(ILogger logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic) { _logger = logger; _mediaFileLogic = mediaFileLogic; _productLogic = productLogic; } [HttpGet] public List GetFullList() { try { return _mediaFileLogic.ReadList(null); } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка продуктов"); throw; } } [HttpGet] public Dictionary> GetByProducts() { try { var dict = new Dictionary>(); var products = _productLogic.ReadList(null); foreach (var product in products) { var media = _mediaFileLogic.ReadList(new MediaFileSearchModel() { ProductId = product.Id, }); dict.Add(product.Id, media); } return dict; } catch (Exception ex) { _logger.LogError(ex, "Ошибка получения списка продуктов"); throw; } } } }