Flip ITrackService/TrackManager to DTO output; TrackConverter is the sole entity<->DTO path across all consumers
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using DeepDrftModels.Entities;
|
||||
using DeepDrftModels.DTOs;
|
||||
using Models.Common;
|
||||
using NetBlocks.Models;
|
||||
using System.Text.Json;
|
||||
@@ -16,7 +16,7 @@ public class TrackClient
|
||||
_http = httpClientFactory.CreateClient("DeepDrft.API");
|
||||
}
|
||||
|
||||
public async Task<ApiResult<PagedResult<TrackEntity>>> GetPage(
|
||||
public async Task<ApiResult<PagedResult<TrackDto>>> GetPage(
|
||||
int pageNumber,
|
||||
int pageSize,
|
||||
string? sortColumn = null,
|
||||
@@ -38,11 +38,11 @@ public class TrackClient
|
||||
var response = await _http.GetAsync($"api/track/page{query}");
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
|
||||
var dto = JsonSerializer.Deserialize<ApiResultDto<PagedResult<TrackEntity>>>(json, new JsonSerializerOptions
|
||||
var dto = JsonSerializer.Deserialize<ApiResultDto<PagedResult<TrackDto>>>(json, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
|
||||
return dto?.From() ?? ApiResult<PagedResult<TrackEntity>>.CreateFailResult("Failed to deserialize response");
|
||||
return dto?.From() ?? ApiResult<PagedResult<TrackDto>>.CreateFailResult("Failed to deserialize response");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using DeepDrftModels.Entities;
|
||||
using DeepDrftModels.DTOs;
|
||||
using DeepDrftPublic.Client.Services;
|
||||
using DeepDrftPublic.Client.ViewModels;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
@@ -11,7 +11,7 @@ public partial class TracksView : ComponentBase
|
||||
[Inject] public required TracksViewModel ViewModel { get; set; }
|
||||
[CascadingParameter] public required IPlayerService PlayerService { get; set; }
|
||||
|
||||
private TrackEntity? _selectedTrack = null;
|
||||
private TrackDto? _selectedTrack = null;
|
||||
private int _clickCount = 0;
|
||||
private string _lifecycleStatus = "Not initialized";
|
||||
|
||||
@@ -40,14 +40,14 @@ public partial class TracksView : ComponentBase
|
||||
{
|
||||
var result = await ViewModel.TrackData.GetPage(newPage, ViewModel.PageSize, ViewModel.SortBy, ViewModel.IsDescending);
|
||||
|
||||
if (result is { Success: true, Value: PagedResult<TrackEntity> pageResult })
|
||||
if (result is { Success: true, Value: PagedResult<TrackDto> pageResult })
|
||||
{
|
||||
ViewModel.Page = pageResult;
|
||||
ViewModel.PageSize = pageResult.PageSize;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PlayTrack(TrackEntity? track)
|
||||
private async Task PlayTrack(TrackDto? track)
|
||||
{
|
||||
if (track == null && _selectedTrack == null || track?.Id == _selectedTrack?.Id) return;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using DeepDrftModels.Entities;
|
||||
using DeepDrftModels.DTOs;
|
||||
using DeepDrftPublic.Client.Clients;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using NetBlocks.Models;
|
||||
@@ -32,7 +32,7 @@ public abstract class AudioPlayerService : IPlayerService, IAsyncDisposable
|
||||
/// <see cref="SelectTrack"/>/<see cref="Unload"/> path are responsible for managing
|
||||
/// it themselves.
|
||||
/// </summary>
|
||||
public TrackEntity? CurrentTrack { get; protected set; }
|
||||
public TrackDto? CurrentTrack { get; protected set; }
|
||||
|
||||
// Events
|
||||
public EventCallback? OnStateChanged { get; set; }
|
||||
@@ -74,7 +74,7 @@ public abstract class AudioPlayerService : IPlayerService, IAsyncDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task SelectTrack(TrackEntity track)
|
||||
public virtual async Task SelectTrack(TrackDto track)
|
||||
{
|
||||
await EnsureInitializedAsync();
|
||||
|
||||
@@ -87,7 +87,7 @@ public abstract class AudioPlayerService : IPlayerService, IAsyncDisposable
|
||||
await NotifyStateChanged();
|
||||
}
|
||||
|
||||
private async Task LoadTrack(TrackEntity track)
|
||||
private async Task LoadTrack(TrackDto track)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using DeepDrftModels.Entities;
|
||||
using DeepDrftModels.DTOs;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using NetBlocks.Models;
|
||||
|
||||
@@ -17,7 +17,7 @@ public interface IPlayerService
|
||||
double Volume { get; }
|
||||
double LoadProgress { get; }
|
||||
string? ErrorMessage { get; }
|
||||
TrackEntity? CurrentTrack { get; }
|
||||
TrackDto? CurrentTrack { get; }
|
||||
|
||||
// Events for UI updates
|
||||
EventCallback? OnStateChanged { get; set; }
|
||||
@@ -25,7 +25,7 @@ public interface IPlayerService
|
||||
|
||||
// Control methods
|
||||
Task InitializeAsync();
|
||||
Task SelectTrack(TrackEntity track);
|
||||
Task SelectTrack(TrackDto track);
|
||||
Task Stop();
|
||||
Task Unload();
|
||||
Task TogglePlayPause();
|
||||
@@ -43,5 +43,5 @@ public interface IStreamingPlayerService : IPlayerService
|
||||
int BufferedChunks { get; }
|
||||
|
||||
// Streaming control methods
|
||||
Task SelectTrackStreaming(TrackEntity track);
|
||||
Task SelectTrackStreaming(TrackDto track);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using DeepDrftModels.Entities;
|
||||
using DeepDrftModels.DTOs;
|
||||
using Models.Common;
|
||||
using NetBlocks.Models;
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace DeepDrftPublic.Client.Services;
|
||||
/// </summary>
|
||||
public interface ITrackDataService
|
||||
{
|
||||
Task<ApiResult<PagedResult<TrackEntity>>> GetPage(
|
||||
Task<ApiResult<PagedResult<TrackDto>>> GetPage(
|
||||
int pageNumber,
|
||||
int pageSize,
|
||||
string? sortColumn = null,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using DeepDrftModels.Entities;
|
||||
using DeepDrftModels.DTOs;
|
||||
using DeepDrftPublic.Client.Clients;
|
||||
using System.Buffers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -41,12 +41,12 @@ public class StreamingAudioPlayerService : AudioPlayerService, IStreamingPlayerS
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override async Task SelectTrack(TrackEntity track)
|
||||
public override async Task SelectTrack(TrackDto track)
|
||||
{
|
||||
await SelectTrackStreaming(track);
|
||||
}
|
||||
|
||||
public async Task SelectTrackStreaming(TrackEntity track)
|
||||
public async Task SelectTrackStreaming(TrackDto track)
|
||||
{
|
||||
await EnsureInitializedAsync();
|
||||
|
||||
@@ -59,7 +59,7 @@ public class StreamingAudioPlayerService : AudioPlayerService, IStreamingPlayerS
|
||||
await NotifyStateChanged();
|
||||
}
|
||||
|
||||
private async Task LoadTrackStreaming(TrackEntity track)
|
||||
private async Task LoadTrackStreaming(TrackDto track)
|
||||
{
|
||||
// Always reset to clean state before loading new track. ResetToIdle
|
||||
// both cancels and awaits any in-flight streaming loop, so by the time
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using DeepDrftModels.Entities;
|
||||
using DeepDrftModels.DTOs;
|
||||
using DeepDrftPublic.Client.Clients;
|
||||
using Models.Common;
|
||||
using NetBlocks.Models;
|
||||
@@ -19,7 +19,7 @@ public class TrackClientDataService : ITrackDataService
|
||||
_trackClient = trackClient;
|
||||
}
|
||||
|
||||
public Task<ApiResult<PagedResult<TrackEntity>>> GetPage(
|
||||
public Task<ApiResult<PagedResult<TrackDto>>> GetPage(
|
||||
int pageNumber,
|
||||
int pageSize,
|
||||
string? sortColumn = null,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using DeepDrftModels.Entities;
|
||||
using DeepDrftModels.DTOs;
|
||||
using DeepDrftPublic.Client.Services;
|
||||
using Models.Common;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class TracksViewModel
|
||||
get => Page?.PageSize ?? 15;
|
||||
set
|
||||
{
|
||||
if (Page == null) throw new Exception();
|
||||
if (Page == null) return;
|
||||
if (value != Page.PageSize)
|
||||
{
|
||||
Page.PageSize = value;
|
||||
@@ -24,7 +24,7 @@ public class TracksViewModel
|
||||
}
|
||||
public string SortBy { get; set; } = string.Empty;
|
||||
public bool IsDescending { get; set; } = false;
|
||||
public PagedResult<TrackEntity>? Page { get; set; } = null;
|
||||
public PagedResult<TrackDto>? Page { get; set; } = null;
|
||||
|
||||
public TracksViewModel(ITrackDataService trackData)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user