[ADD] Added endpoint for providing files
This commit is contained in:
22
Manager.App/Controllers/FileController.cs
Normal file
22
Manager.App/Controllers/FileController.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Manager.App.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Manager.App.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/v1/[controller]")]
|
||||
public class FileController(ILibraryService libraryService) : ControllerBase
|
||||
{
|
||||
[HttpGet("provide")]
|
||||
public async Task<IActionResult> ProvideFile([FromQuery(Name = "id")] Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var fileResult = await libraryService.GetFileByIdAsync(id, cancellationToken);
|
||||
if (!fileResult.IsSuccess)
|
||||
{
|
||||
return BadRequest(fileResult.Error);
|
||||
}
|
||||
|
||||
var libFile = fileResult.Value;
|
||||
return File(libFile.DataStream, libFile.MimeType, libFile.FileName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user