Fix 9 design majors: ITrackService interface, IsDescending, ArrayPool base, CliUtils, sort sentinel cleanup, content controller via TrackService, Skip property

This commit is contained in:
Daniel Harvey
2026-05-17 16:10:56 -04:00
parent fc5b8de81a
commit 4c9bf0ca8d
15 changed files with 97 additions and 71 deletions
+15
View File
@@ -0,0 +1,15 @@
using DeepDrftModels.Entities;
using DeepDrftModels.Models;
using NetBlocks.Models;
namespace DeepDrftWeb.Services;
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<TrackEntity>> Create(TrackEntity newTrack);
Task<ResultContainer<TrackEntity>> Update(TrackEntity track);
Task<Result> Delete(long id);
}
@@ -26,11 +26,18 @@ public class TrackRepository
public async Task<PagedResult<TrackEntity>> GetPage(PagingParameters<TrackEntity> pageParameters)
{
// Two separate queries with no transaction: count and page can be momentarily inconsistent
// under concurrent writes. Acceptable — SQLite concurrency 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 page = await _db.Tracks
.OrderBy(pageParameters.OrderBy ?? (t => t.Id))
.Skip((pageParameters.Page - 1) * pageParameters.PageSize)
var orderBy = pageParameters.OrderBy ?? (t => t.Id);
var ordered = pageParameters.IsDescending
? _db.Tracks.OrderByDescending(orderBy)
: _db.Tracks.OrderBy(orderBy);
var page = await ordered
.Skip(pageParameters.Skip)
.Take(pageParameters.PageSize)
.ToListAsync();
+3 -5
View File
@@ -6,10 +6,8 @@ using NetBlocks.Models;
namespace DeepDrftWeb.Services;
public class TrackService
public class TrackService : ITrackService
{
private readonly string _sortLastAscending = Enumerable.Repeat(char.MaxValue, 64).Aggregate(string.Empty, (a, b) => a + b);
private readonly string _sortLastDescending = Enumerable.Repeat(char.MinValue.ToString(), 64).Aggregate(string.Empty, (a, b) => a + b);
private readonly TrackRepository _repository;
public TrackService(TrackRepository repository)
@@ -65,13 +63,13 @@ public class TrackService
parameters.OrderBy = entity => entity.Artist;
break;
case "Album":
parameters.OrderBy = entity => entity.Album ?? _sortLastAscending;
parameters.OrderBy = entity => entity.Album ?? "";
break;
case "ReleaseDate":
parameters.OrderBy = entity => entity.ReleaseDate ?? DateOnly.MaxValue;
break;
case "Genre":
parameters.OrderBy = entity => entity.Genre ?? _sortLastAscending;
parameters.OrderBy = entity => entity.Genre ?? "";
break;
}