|
|
@@ -1,3 +1,4 @@
|
|
|
+using System.Security.Claims;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using RunnersMeet.Server.Domain;
|
|
|
using RunnersMeet.Server.Persistence;
|
|
|
@@ -8,10 +9,12 @@ namespace RunnersMeet.Server.Controllers;
|
|
|
[ApiController]
|
|
|
public class TracksController : ControllerBase
|
|
|
{
|
|
|
+ private readonly IFileStorage _fileStorage;
|
|
|
private readonly QueryFactory _queryFactory;
|
|
|
|
|
|
- public TracksController(QueryFactory queryFactory)
|
|
|
+ public TracksController(IFileStorage fileStorage, QueryFactory queryFactory)
|
|
|
{
|
|
|
+ _fileStorage = fileStorage;
|
|
|
_queryFactory = queryFactory;
|
|
|
}
|
|
|
|
|
|
@@ -20,4 +23,15 @@ public class TracksController : ControllerBase
|
|
|
{
|
|
|
return Ok(_queryFactory.TracksQuery().Get());
|
|
|
}
|
|
|
+
|
|
|
+ [HttpPost]
|
|
|
+ public async Task<ActionResult<Track>> CreateTrack([FromForm] IFormFile file, [FromForm] string? name, CancellationToken cancellationToken = default)
|
|
|
+ {
|
|
|
+ var fileName = await _fileStorage.UploadFileAsync(file, name, cancellationToken);
|
|
|
+
|
|
|
+ var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? "<unknown>";
|
|
|
+ var track = _queryFactory.CreateTrackCommand().Create(userId, fileName);
|
|
|
+
|
|
|
+ return Ok(track);
|
|
|
+ }
|
|
|
}
|