using DomainResults.Mvc; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Net.Http.Headers; using WeatherForecast.Services; namespace WeatherForecast.Controllers { /// /// /// [ApiController] [AllowAnonymous] [Route("api/[controller]")] public class FileController : Controller { private readonly IFileService _fileService; /// /// /// /// public FileController( IFileService fileService ) { _fileService = fileService; } /// /// /// /// /// /// /// [HttpGet("{siteId}/{userId}/{fileId}")] public IActionResult Get([FromRoute] Guid siteId, [FromRoute] Guid userid, [FromRoute] Guid fileId) { var (file, result) = _fileService.Get(siteId, userid, fileId); if (!result.IsSuccess || file == null) return result.ToActionResult(); var stream = new MemoryStream(file.Bytes); return new FileStreamResult(stream, file.ContentType) { FileDownloadName = file.Name }; } /// /// /// /// /// /// /// [HttpDelete("{siteId}/{userId}/{fileId}")] public IActionResult Delete([FromRoute] Guid siteId, [FromRoute] Guid userId, [FromRoute] Guid fileId) { var result = _fileService.Delete(siteId, userId, fileId); return result.ToActionResult(); } } }