Flip ITrackService/TrackManager to DTO output; TrackConverter is the sole entity<->DTO path across all consumers
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using DeepDrftModels.Entities;
|
||||
using DeepDrftModels.DTOs;
|
||||
using Models.Common;
|
||||
using NetBlocks.Models;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class CmsTrackService : ICmsTrackService
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<ResultContainer<TrackEntity>> UploadTrackAsync(
|
||||
public async Task<ResultContainer<TrackDto>> UploadTrackAsync(
|
||||
Stream wavStream,
|
||||
string fileName,
|
||||
string contentType,
|
||||
@@ -67,7 +67,7 @@ public class CmsTrackService : ICmsTrackService
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Content API call failed for upload of {TrackName}", trackName);
|
||||
return ResultContainer<TrackEntity>.CreateFailResult("Content API is unreachable.");
|
||||
return ResultContainer<TrackDto>.CreateFailResult("Content API is unreachable.");
|
||||
}
|
||||
|
||||
using (response)
|
||||
@@ -79,35 +79,35 @@ public class CmsTrackService : ICmsTrackService
|
||||
if (statusCode >= 500)
|
||||
{
|
||||
_logger.LogError("Content API returned {Status} for upload of {TrackName}: {Body}", statusCode, trackName, body);
|
||||
return ResultContainer<TrackEntity>.CreateFailResult("Upload failed on the content server. Please try again.");
|
||||
return ResultContainer<TrackDto>.CreateFailResult("Upload failed on the content server. Please try again.");
|
||||
}
|
||||
|
||||
// 4xx: body is user-friendly validation text from DeepDrftAPI — relay as-is.
|
||||
_logger.LogWarning("Content API rejected upload: {Status} {Body}", statusCode, body);
|
||||
return ResultContainer<TrackEntity>.CreateFailResult(
|
||||
return ResultContainer<TrackDto>.CreateFailResult(
|
||||
string.IsNullOrWhiteSpace(body) ? $"Upload rejected ({statusCode})." : body);
|
||||
}
|
||||
|
||||
// The Content API now owns the dual-database write, so the response is the persisted
|
||||
// entity (Id > 0) — no SQL roundtrip here.
|
||||
TrackEntity? persisted;
|
||||
// track DTO (Id > 0) — no SQL roundtrip here.
|
||||
TrackDto? persisted;
|
||||
try
|
||||
{
|
||||
persisted = await response.Content.ReadFromJsonAsync<TrackEntity>(ct);
|
||||
persisted = await response.Content.ReadFromJsonAsync<TrackDto>(ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to deserialize TrackEntity from Content API response");
|
||||
return ResultContainer<TrackEntity>.CreateFailResult("Content API returned an unexpected response.");
|
||||
_logger.LogError(ex, "Failed to deserialize TrackDto from Content API response");
|
||||
return ResultContainer<TrackDto>.CreateFailResult("Content API returned an unexpected response.");
|
||||
}
|
||||
|
||||
if (persisted is null)
|
||||
{
|
||||
_logger.LogError("Content API returned a null TrackEntity");
|
||||
return ResultContainer<TrackEntity>.CreateFailResult("Content API returned an empty response.");
|
||||
_logger.LogError("Content API returned a null TrackDto");
|
||||
return ResultContainer<TrackDto>.CreateFailResult("Content API returned an empty response.");
|
||||
}
|
||||
|
||||
return ResultContainer<TrackEntity>.CreatePassResult(persisted);
|
||||
return ResultContainer<TrackDto>.CreatePassResult(persisted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public class CmsTrackService : ICmsTrackService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ResultContainer<PagedResult<TrackEntity>>> GetPagedAsync(
|
||||
public async Task<ResultContainer<PagedResult<TrackDto>>> GetPagedAsync(
|
||||
int page, int pageSize, string? sortColumn, bool sortDescending,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
@@ -163,7 +163,7 @@ public class CmsTrackService : ICmsTrackService
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Content API call failed for track page");
|
||||
return ResultContainer<PagedResult<TrackEntity>>.CreateFailResult("Content API is unreachable.");
|
||||
return ResultContainer<PagedResult<TrackDto>>.CreateFailResult("Content API is unreachable.");
|
||||
}
|
||||
|
||||
using (response)
|
||||
@@ -171,31 +171,31 @@ public class CmsTrackService : ICmsTrackService
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogError("Content API track page failed: {Status}", (int)response.StatusCode);
|
||||
return ResultContainer<PagedResult<TrackEntity>>.CreateFailResult("Failed to load tracks.");
|
||||
return ResultContainer<PagedResult<TrackDto>>.CreateFailResult("Failed to load tracks.");
|
||||
}
|
||||
|
||||
PagedResult<TrackEntity>? paged;
|
||||
PagedResult<TrackDto>? paged;
|
||||
try
|
||||
{
|
||||
paged = await response.Content.ReadFromJsonAsync<PagedResult<TrackEntity>>(ct);
|
||||
paged = await response.Content.ReadFromJsonAsync<PagedResult<TrackDto>>(ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to deserialize PagedResult from Content API response");
|
||||
return ResultContainer<PagedResult<TrackEntity>>.CreateFailResult("Content API returned an unexpected response.");
|
||||
return ResultContainer<PagedResult<TrackDto>>.CreateFailResult("Content API returned an unexpected response.");
|
||||
}
|
||||
|
||||
if (paged is null)
|
||||
{
|
||||
_logger.LogError("Content API returned a null PagedResult");
|
||||
return ResultContainer<PagedResult<TrackEntity>>.CreateFailResult("Content API returned an empty response.");
|
||||
return ResultContainer<PagedResult<TrackDto>>.CreateFailResult("Content API returned an empty response.");
|
||||
}
|
||||
|
||||
return ResultContainer<PagedResult<TrackEntity>>.CreatePassResult(paged);
|
||||
return ResultContainer<PagedResult<TrackDto>>.CreatePassResult(paged);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ResultContainer<TrackEntity?>> GetByIdAsync(long id, CancellationToken ct = default)
|
||||
public async Task<ResultContainer<TrackDto?>> GetByIdAsync(long id, CancellationToken ct = default)
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient(ContentCmsClientName);
|
||||
|
||||
@@ -207,34 +207,34 @@ public class CmsTrackService : ICmsTrackService
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Content API call failed for track {TrackId}", id);
|
||||
return ResultContainer<TrackEntity?>.CreateFailResult("Content API is unreachable.");
|
||||
return ResultContainer<TrackDto?>.CreateFailResult("Content API is unreachable.");
|
||||
}
|
||||
|
||||
using (response)
|
||||
{
|
||||
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
return ResultContainer<TrackEntity?>.CreatePassResult(null);
|
||||
return ResultContainer<TrackDto?>.CreatePassResult(null);
|
||||
}
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogError("Content API track lookup failed for {TrackId}: {Status}", id, (int)response.StatusCode);
|
||||
return ResultContainer<TrackEntity?>.CreateFailResult("Failed to load track.");
|
||||
return ResultContainer<TrackDto?>.CreateFailResult("Failed to load track.");
|
||||
}
|
||||
|
||||
TrackEntity? track;
|
||||
TrackDto? track;
|
||||
try
|
||||
{
|
||||
track = await response.Content.ReadFromJsonAsync<TrackEntity>(ct);
|
||||
track = await response.Content.ReadFromJsonAsync<TrackDto>(ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to deserialize TrackEntity from Content API response");
|
||||
return ResultContainer<TrackEntity?>.CreateFailResult("Content API returned an unexpected response.");
|
||||
_logger.LogError(ex, "Failed to deserialize TrackDto from Content API response");
|
||||
return ResultContainer<TrackDto?>.CreateFailResult("Content API returned an unexpected response.");
|
||||
}
|
||||
|
||||
return ResultContainer<TrackEntity?>.CreatePassResult(track);
|
||||
return ResultContainer<TrackDto?>.CreatePassResult(track);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using DeepDrftModels.Entities;
|
||||
using DeepDrftModels.DTOs;
|
||||
using Models.Common;
|
||||
using NetBlocks.Models;
|
||||
|
||||
@@ -13,10 +13,10 @@ public interface ICmsTrackService
|
||||
{
|
||||
/// <summary>
|
||||
/// Proxy a WAV upload to DeepDrftAPI. The Content API owns the dual-database write and
|
||||
/// returns the persisted entity carrying the SQL-assigned <c>Id</c>. A vault-without-SQL
|
||||
/// returns the persisted track carrying the SQL-assigned <c>Id</c>. A vault-without-SQL
|
||||
/// orphan is handled and logged server-side; here it surfaces as a failed result.
|
||||
/// </summary>
|
||||
Task<ResultContainer<TrackEntity>> UploadTrackAsync(
|
||||
Task<ResultContainer<TrackDto>> UploadTrackAsync(
|
||||
Stream wavStream,
|
||||
string fileName,
|
||||
string contentType,
|
||||
@@ -37,7 +37,7 @@ public interface ICmsTrackService
|
||||
/// <summary>
|
||||
/// Fetch a page of track metadata from the Content API's <c>GET api/track/page</c>.
|
||||
/// </summary>
|
||||
Task<ResultContainer<PagedResult<TrackEntity>>> GetPagedAsync(
|
||||
Task<ResultContainer<PagedResult<TrackDto>>> GetPagedAsync(
|
||||
int page, int pageSize, string? sortColumn, bool sortDescending,
|
||||
CancellationToken ct = default);
|
||||
|
||||
@@ -45,7 +45,7 @@ public interface ICmsTrackService
|
||||
/// Fetch a single track's metadata from <c>GET api/track/meta/{id}</c>. A 404 returns a
|
||||
/// passing result with a null value.
|
||||
/// </summary>
|
||||
Task<ResultContainer<TrackEntity?>> GetByIdAsync(long id, CancellationToken ct = default);
|
||||
Task<ResultContainer<TrackDto?>> GetByIdAsync(long id, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Update a track's metadata via <c>PUT api/track/meta/{id}</c>. EntryKey is immutable and
|
||||
|
||||
Reference in New Issue
Block a user