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