diff --git a/src/WishNinja/Components/Pages/Admin/Invites.razor b/src/WishNinja/Components/Pages/Admin/Invites.razor index 1e26b31..6db4e08 100644 --- a/src/WishNinja/Components/Pages/Admin/Invites.razor +++ b/src/WishNinja/Components/Pages/Admin/Invites.razor @@ -102,7 +102,7 @@ else await using var db = await DbFactory.CreateDbContextAsync(); pending = await db.Invites .Where(i => i.AcceptedAt == null) - .OrderByDescending(i => i.CreatedAt) + .OrderByDescending(i => i.Id) // Id grows with creation; SQLite can't ORDER BY DateTimeOffset .ToListAsync(); } diff --git a/src/WishNinja/Components/Pages/Wishlists.razor b/src/WishNinja/Components/Pages/Wishlists.razor index 4d357fd..a574d18 100644 --- a/src/WishNinja/Components/Pages/Wishlists.razor +++ b/src/WishNinja/Components/Pages/Wishlists.razor @@ -79,7 +79,7 @@ else owned = await db.Wishlists .Include(w => w.Items) .Where(w => w.OwnerId == userId) - .OrderByDescending(w => w.CreatedAt) + .OrderByDescending(w => w.Id) // Id grows with creation; SQLite can't ORDER BY DateTimeOffset .ToListAsync(); } diff --git a/src/WishNinja/Services/WishlistService.cs b/src/WishNinja/Services/WishlistService.cs index 561d82c..4f84eee 100644 --- a/src/WishNinja/Services/WishlistService.cs +++ b/src/WishNinja/Services/WishlistService.cs @@ -21,7 +21,7 @@ public class WishlistService(IDbContextFactory dbFactory) await using var db = await dbFactory.CreateDbContextAsync(); return await db.Wishlists .Where(w => w.OwnerId == userId) - .OrderByDescending(w => w.CreatedAt) + .OrderByDescending(w => w.Id) // Id grows with creation; SQLite can't ORDER BY DateTimeOffset .ToListAsync(); } diff --git a/tests/WishNinja.Tests/WishlistServiceTests.cs b/tests/WishNinja.Tests/WishlistServiceTests.cs index e9ffd7e..841c3c9 100644 --- a/tests/WishNinja.Tests/WishlistServiceTests.cs +++ b/tests/WishNinja.Tests/WishlistServiceTests.cs @@ -144,5 +144,17 @@ public class WishlistServiceTests : IDisposable Assert.NotNull(await _svc.GetDetailAsync(1, OwnerId)); // owner always } + [Fact] + public async Task Owned_and_shared_list_queries_run_on_sqlite() + { + // Regression: these order by a timestamp; SQLite can't ORDER BY DateTimeOffset, so the + // service must order by a supported column. This would throw NotSupportedException otherwise. + var owned = await _svc.GetOwnedAsync(OwnerId); + Assert.Single(owned); + + var shared = await _svc.GetSharedWithAsync(FriendId); + Assert.Single(shared); // the AllMembers list is visible to other members + } + public void Dispose() => _db.Dispose(); }