Add ActionsFilter

This commit is contained in:
2025-10-16 20:58:28 +02:00
parent c2b0c0d02b
commit ea18e35c31
3 changed files with 52 additions and 15 deletions

View File

@@ -31,4 +31,24 @@ public class ActionsContext(DbContextOptions<ActionsContext> options) : TrangaBa
modelBuilder.Entity<LibraryMovedActionRecord>().Property(a => a.MangaId).HasColumnName("MangaId");
}
public IQueryable<ActionRecord> FilterManga(string MangaId) => this.Actions
.FromSqlInterpolated($"""SELECT * FROM public."Actions" WHERE "MangaId" = {MangaId}""");
public IQueryable<ActionRecord> FilterChapter(string ChapterId) => this.Actions
.FromSqlInterpolated($"""SELECT * FROM public."Actions" WHERE "ChapterId" = {ChapterId}""");
public IQueryable<ActionRecord> FilterMangaAndChapter(string MangaId, string ChapterId) => this.Actions
.FromSqlInterpolated($"""SELECT * FROM public."Actions" WHERE "MangaId" = {MangaId} AND "ChapterId" = {ChapterId}""");
public IQueryable<ActionRecord> Filter(string? MangaId, string? ChapterId)
{
if (MangaId is { } mangaId && ChapterId is { } chapterId)
return FilterMangaAndChapter(mangaId, chapterId);
if (MangaId is { } mangaId2)
return FilterManga(mangaId2);
if (ChapterId is { } chapterId2)
return FilterChapter(chapterId2);
return this.Actions.AsQueryable();
}
}