Fix Actions that can have related chapters and manga

This commit is contained in:
2025-10-16 20:28:43 +02:00
parent d029512354
commit ef907ee09d
15 changed files with 75 additions and 49 deletions

View File

@@ -69,7 +69,7 @@ public class ActionsController(ActionsContext context) : Controller
[ProducesResponseType(Status500InternalServerError)]
public async Task<Results<Ok<IEnumerable<ActionRecord>>, InternalServerError>> GetActionsRelatedToManga(string MangaId)
{
if(await context.Actions.FromSqlInterpolated($"""SELECT * FROM public."Actions" WHERE "MangaId" = {MangaId}""").ToListAsync() is not { } actions)
if(await context.Actions.FromSqlInterpolated($"""SELECT * FROM public."Actions" WHERE "MangaId" = {MangaId}""").ToListAsync(HttpContext.RequestAborted) is not { } actions)
return TypedResults.InternalServerError();
return TypedResults.Ok(actions.Select(a => new ActionRecord(a)));
@@ -85,7 +85,7 @@ public class ActionsController(ActionsContext context) : Controller
[ProducesResponseType(Status500InternalServerError)]
public async Task<Results<Ok<IEnumerable<ActionRecord>>, InternalServerError>> GetActionsRelatedToChapter(string ChapterId)
{
if(await context.Actions.FromSqlInterpolated($"""SELECT * FROM public."Actions" WHERE "ChapterId" = {ChapterId}""").ToListAsync() is not { } actions)
if(await context.Actions.FromSqlInterpolated($"""SELECT * FROM public."Actions" WHERE "ChapterId" = {ChapterId}""").ToListAsync(HttpContext.RequestAborted) is not { } actions)
return TypedResults.InternalServerError();
return TypedResults.Ok(actions.Select(a => new ActionRecord(a)));

View File

@@ -11,8 +11,8 @@ public sealed record ActionRecord : Identifiable
{
Action = actionRecord.Action;
PerformedAt = actionRecord.PerformedAt;
MangaId = actionRecord is ActionWithMangaRecord m ? m.MangaId : null;
ChapterId = actionRecord is ActionWithChapterRecord c ? c.ChapterId : null;
MangaId = actionRecord is IActionWithMangaRecord m ? m.MangaId : null;
ChapterId = actionRecord is IActionWithChapterRecord c ? c.ChapterId : null;
}
/// <summary>
@@ -28,13 +28,13 @@ public sealed record ActionRecord : Identifiable
public DateTime PerformedAt { get; init; }
/// <summary>
/// MangaId if Record is <see cref="ActionWithMangaRecord"/>
/// MangaId if Record is <see cref="IActionWithMangaRecord"/>
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? MangaId { get; init; }
/// <summary>
/// ChapterId if Record is <see cref="ActionWithMangaRecord"/>
/// ChapterId if Record is <see cref="IActionWithMangaRecord"/>
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? ChapterId { get; init; }