PIAPS_CW/RestAPI/Controllers/MediaFileController.cs

64 lines
2.0 KiB
C#
Raw Permalink Normal View History

2024-06-25 20:26:34 +04:00
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
{
2024-06-25 20:26:34 +04:00
[Route("[controller]/[action]")]
[ApiController]
public class MediaFileController : Controller
{
private readonly IMediaFileLogic _mediaFileLogic;
private readonly IProductLogic _productLogic;
private readonly ILogger _logger;
2024-06-26 08:04:07 +04:00
public MediaFileController(ILogger<MediaFileController> logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic)
{
_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()
{
try
{
2024-06-25 20:26:34 +04:00
var dict = new Dictionary<Guid, List<MediaFileViewModel>>();
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);
}
return dict;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка продуктов");
throw;
}
}
}
}