Content API Upgrades

This commit is contained in:
daniel-c-harvey
2025-09-04 19:58:29 -04:00
parent 9de2063ea3
commit 1a9a3271d4
14 changed files with 394 additions and 65 deletions
+14 -8
View File
@@ -1,5 +1,7 @@
using DeepDrftContent.FileDatabase.Models;
using DeepDrftContent.Constants;
using DeepDrftContent.FileDatabase.Models;
using DeepDrftContent.FileDatabase.Services;
using DeepDrftContent.Middleware;
using Microsoft.AspNetCore.Mvc;
namespace DeepDrftContent.Controllers;
@@ -16,15 +18,19 @@ public class TrackController : ControllerBase
}
[HttpGet("{trackId}")]
public async Task<ActionResult<AudioBinaryDto>> GetTrack([FromQuery] string trackId)
public async Task<ActionResult> GetTrack(string trackId)
{
// BEFORE: Complex with EntryKey objects and redundant MediaVaultType
// var entryKey = new EntryKey(trackId, MediaVaultTypeMap.GetVaultType<AudioBinary>());
// var file = await _fileDatabase.LoadResourceAsync<AudioBinary>(_vaultKey, entryKey);
// AFTER: Ultra clean - just string identifiers, types inferred
var file = await _fileDatabase.LoadResourceAsync<AudioBinary>("tracks", trackId);
var file = await _fileDatabase.LoadResourceAsync<AudioBinary>(VaultConstants.Tracks, trackId);
if (file == null) { return NotFound(); }
return File(file.Buffer, MimeTypeExtensions.GetMimeType(file.Extension));
}
[ApiKeyAuthorize]
[HttpPut("{trackId}")]
public async Task<ActionResult> PutTrack([FromQuery] string trackId, [FromBody] AudioBinaryDto track)
{
var audioBinary = AudioBinary.From(track);
var success = await _fileDatabase.RegisterResourceAsync(VaultConstants.Tracks, trackId, audioBinary);
return success ? Ok() : BadRequest("Failed to store audio track");
}
}
@@ -1,32 +0,0 @@
using Microsoft.AspNetCore.Mvc;
namespace DeepDrftContent.Controllers;
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}