using System.Threading.Tasks;
using API.Extensions;
using API.Interfaces;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers
{
///
/// Responsible for servicing up images stored in the DB
///
public class ImageController : BaseApiController
{
private const string Format = "jpeg";
private readonly IUnitOfWork _unitOfWork;
///
public ImageController(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
///
/// Returns cover image for Chapter
///
///
///
[HttpGet("chapter-cover")]
public async Task GetChapterCoverImage(int chapterId)
{
var content = await _unitOfWork.VolumeRepository.GetChapterCoverImageAsync(chapterId);
if (content == null) return BadRequest("No cover image");
Response.AddCacheHeader(content);
return File(content, "image/" + Format, $"{chapterId}");
}
///
/// Returns cover image for Volume
///
///
///
[HttpGet("volume-cover")]
public async Task GetVolumeCoverImage(int volumeId)
{
var content = await _unitOfWork.SeriesRepository.GetVolumeCoverImageAsync(volumeId);
if (content == null) return BadRequest("No cover image");
Response.AddCacheHeader(content);
return File(content, "image/" + Format, $"{volumeId}");
}
///
/// Returns cover image for Series
///
/// Id of Series
///
[HttpGet("series-cover")]
public async Task GetSeriesCoverImage(int seriesId)
{
var content = await _unitOfWork.SeriesRepository.GetSeriesCoverImageAsync(seriesId);
if (content == null) return BadRequest("No cover image");
Response.AddCacheHeader(content);
return File(content, "image/" + Format, $"{seriesId}");
}
///
/// Returns cover image for Collection Tag
///
///
///
[HttpGet("collection-cover")]
public async Task GetCollectionCoverImage(int collectionTagId)
{
var content = await _unitOfWork.CollectionTagRepository.GetCoverImageAsync(collectionTagId);
if (content == null) return BadRequest("No cover image");
Response.AddCacheHeader(content);
return File(content, "image/" + Format, $"{collectionTagId}");
}
}
}