Fix W3-T1 review: forward CancellationToken in GetPaged, scrub ex.Message from snackbar, drop unused Navigation inject, annotate ITrackService wiring in CmsStartup
This commit is contained in:
@@ -7,6 +7,11 @@ public static class CmsStartup
|
||||
public static IServiceCollection AddCmsServices(this IServiceCollection services)
|
||||
{
|
||||
// CMS-specific services registered here as implementation waves land.
|
||||
//
|
||||
// Note: ITrackService (and its dependencies: TrackRepository, DeepDrftContext) is registered
|
||||
// by DeepDrftWeb.Startup.ConfigureDomainServices, not here. The CMS RCL runs inside the
|
||||
// DeepDrftWeb host, which wires those up before this method is called. A standalone CMS
|
||||
// host would need to register ITrackService separately.
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
@inject NavigationManager Navigation
|
||||
@inject ILogger<TrackList> Logger
|
||||
|
||||
<PageTitle>Tracks — DeepDrft CMS</PageTitle>
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
var sortColumn = string.IsNullOrEmpty(state.SortLabel) ? "TrackName" : state.SortLabel;
|
||||
var sortDescending = state.SortDirection == SortDirection.Descending;
|
||||
|
||||
var result = await TrackService.GetPaged(pageNumber, state.PageSize, sortColumn, sortDescending);
|
||||
var result = await TrackService.GetPaged(pageNumber, state.PageSize, sortColumn, sortDescending, cancellationToken);
|
||||
|
||||
if (!result.Success || result.Value is null)
|
||||
{
|
||||
@@ -129,7 +129,8 @@
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Delete failed: {ex.Message}", Severity.Error);
|
||||
Logger.LogError(ex, "Delete failed for track {TrackId}", track.Id);
|
||||
Snackbar.Add("Delete failed — please try again.", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||
@using Microsoft.Extensions.Logging
|
||||
@using Microsoft.JSInterop
|
||||
@using DeepDrftCms
|
||||
@using DeepDrftModels.Entities
|
||||
|
||||
@@ -8,7 +8,7 @@ public interface ITrackService
|
||||
{
|
||||
Task<ResultContainer<TrackEntity?>> GetById(long id);
|
||||
Task<ResultContainer<List<TrackEntity>>> GetAll();
|
||||
Task<ResultContainer<PagedResult<TrackEntity>>> GetPaged(int pageNumber, int pageSize, string? sortColumn, bool sortDescending);
|
||||
Task<ResultContainer<PagedResult<TrackEntity>>> GetPaged(int pageNumber, int pageSize, string? sortColumn, bool sortDescending, CancellationToken cancellationToken = default);
|
||||
Task<ResultContainer<TrackEntity>> Create(TrackEntity newTrack);
|
||||
Task<ResultContainer<TrackEntity>> Update(TrackEntity track);
|
||||
Task<Result> Delete(long id);
|
||||
|
||||
@@ -24,12 +24,12 @@ public class TrackRepository
|
||||
return await _db.Tracks.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<PagedResult<TrackEntity>> GetPage(PagingParameters<TrackEntity> pageParameters)
|
||||
public async Task<PagedResult<TrackEntity>> GetPage(PagingParameters<TrackEntity> pageParameters, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// Two separate queries with no transaction: count and page can be momentarily inconsistent
|
||||
// under concurrent writes. Acceptable — write volume is low and the UI is read-only.
|
||||
// If filtering is added, the count query must be updated to apply the same filter.
|
||||
var count = await _db.Tracks.CountAsync();
|
||||
var count = await _db.Tracks.CountAsync(cancellationToken);
|
||||
|
||||
var orderBy = pageParameters.OrderBy ?? (t => t.Id);
|
||||
var ordered = pageParameters.IsDescending
|
||||
@@ -39,7 +39,7 @@ public class TrackRepository
|
||||
var page = await ordered
|
||||
.Skip(pageParameters.Skip)
|
||||
.Take(pageParameters.PageSize)
|
||||
.ToListAsync();
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return new PagedResult<TrackEntity>(page, count, pageParameters.Page, pageParameters.PageSize);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TrackService : ITrackService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ResultContainer<PagedResult<TrackEntity>>> GetPaged(int pageNumber, int pageSize, string? sortColumn, bool sortDescending)
|
||||
public async Task<ResultContainer<PagedResult<TrackEntity>>> GetPaged(int pageNumber, int pageSize, string? sortColumn, bool sortDescending, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -75,7 +75,7 @@ public class TrackService : ITrackService
|
||||
}
|
||||
}
|
||||
|
||||
var page = await _repository.GetPage(parameters);
|
||||
var page = await _repository.GetPage(parameters, cancellationToken);
|
||||
return ResultContainer<PagedResult<TrackEntity>>.CreatePassResult(page);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
Reference in New Issue
Block a user