From 9278e7aec4911b976792dbf95c1939af230957d3 Mon Sep 17 00:00:00 2001 From: Artem Lazarchuk Date: Tue, 7 Apr 2026 01:29:20 +0300 Subject: [PATCH] refactor: Replace TestResultEntity with TestRunResultEntity across multiple components, enhancing data consistency and aligning with the new test run results structure --- .../ivy-ask-statistics/Apps/DashboardApp.cs | 2 +- .../Apps/QuestionEditSheet.cs | 2 +- .../ivy-ask-statistics/Apps/RunApp.cs | 4 +-- .../Connections/AppDbContext.cs | 4 +-- .../Connections/QuestionEntity.cs | 2 +- .../Connections/TestRunEntity.cs | 2 +- .../Connections/TestRunResultEntity.cs | 26 +++++++++++++++++++ 7 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 project-demos/ivy-ask-statistics/Connections/TestRunResultEntity.cs diff --git a/project-demos/ivy-ask-statistics/Apps/DashboardApp.cs b/project-demos/ivy-ask-statistics/Apps/DashboardApp.cs index 0f50c4e9..e8f84deb 100644 --- a/project-demos/ivy-ask-statistics/Apps/DashboardApp.cs +++ b/project-demos/ivy-ask-statistics/Apps/DashboardApp.cs @@ -595,7 +595,7 @@ static void FillMetrics( } private static DashboardData BuildDashboardData( - List results, + List results, double? prevAnswerRate, int? prevAvgMs, TestRunEntity? run = null) diff --git a/project-demos/ivy-ask-statistics/Apps/QuestionEditSheet.cs b/project-demos/ivy-ask-statistics/Apps/QuestionEditSheet.cs index f5b1123d..91c24166 100644 --- a/project-demos/ivy-ask-statistics/Apps/QuestionEditSheet.cs +++ b/project-demos/ivy-ask-statistics/Apps/QuestionEditSheet.cs @@ -19,7 +19,7 @@ private record EditRequest } /// - /// Question row plus optional response preview: either the specific row + /// Question row plus optional response preview: either the specific row /// (when opened from a run results table) or the latest answer across all runs (elsewhere). /// private sealed record QuestionEditPayload( diff --git a/project-demos/ivy-ask-statistics/Apps/RunApp.cs b/project-demos/ivy-ask-statistics/Apps/RunApp.cs index 7c87ce09..6b3d280d 100644 --- a/project-demos/ivy-ask-statistics/Apps/RunApp.cs +++ b/project-demos/ivy-ask-statistics/Apps/RunApp.cs @@ -698,13 +698,13 @@ private static async Task PersistNewRunAsync( }; ctx.TestRuns.Add(run); - var rows = new List(ordered.Count); + var rows = new List(ordered.Count); foreach (var result in ordered) { if (!Guid.TryParse(result.Question.Id, out var questionId)) throw new InvalidOperationException($"Invalid question id: {result.Question.Id}"); - rows.Add(new TestResultEntity + rows.Add(new TestRunResultEntity { TestRunId = run.Id, QuestionId = questionId, diff --git a/project-demos/ivy-ask-statistics/Connections/AppDbContext.cs b/project-demos/ivy-ask-statistics/Connections/AppDbContext.cs index 8ddc7ecd..a71465bd 100644 --- a/project-demos/ivy-ask-statistics/Connections/AppDbContext.cs +++ b/project-demos/ivy-ask-statistics/Connections/AppDbContext.cs @@ -6,11 +6,11 @@ public class AppDbContext(DbContextOptions options) : DbContext(op { public DbSet Questions { get; set; } public DbSet TestRuns { get; set; } - public DbSet TestResults { get; set; } + public DbSet TestResults { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity(e => + modelBuilder.Entity(e => { e.HasOne(r => r.TestRun) .WithMany(tr => tr.Results) diff --git a/project-demos/ivy-ask-statistics/Connections/QuestionEntity.cs b/project-demos/ivy-ask-statistics/Connections/QuestionEntity.cs index 35b8e716..de21cd80 100644 --- a/project-demos/ivy-ask-statistics/Connections/QuestionEntity.cs +++ b/project-demos/ivy-ask-statistics/Connections/QuestionEntity.cs @@ -26,5 +26,5 @@ public class QuestionEntity public DateTime CreatedAt { get; set; } = DateTime.UtcNow; - public List TestResults { get; set; } = []; + public List TestResults { get; set; } = []; } diff --git a/project-demos/ivy-ask-statistics/Connections/TestRunEntity.cs b/project-demos/ivy-ask-statistics/Connections/TestRunEntity.cs index 8426f984..563c7158 100644 --- a/project-demos/ivy-ask-statistics/Connections/TestRunEntity.cs +++ b/project-demos/ivy-ask-statistics/Connections/TestRunEntity.cs @@ -29,5 +29,5 @@ public class TestRunEntity public DateTime StartedAt { get; set; } = DateTime.UtcNow; public DateTime? CompletedAt { get; set; } - public List Results { get; set; } = []; + public List Results { get; set; } = []; } diff --git a/project-demos/ivy-ask-statistics/Connections/TestRunResultEntity.cs b/project-demos/ivy-ask-statistics/Connections/TestRunResultEntity.cs new file mode 100644 index 00000000..5564168c --- /dev/null +++ b/project-demos/ivy-ask-statistics/Connections/TestRunResultEntity.cs @@ -0,0 +1,26 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace IvyAskStatistics.Connections; + +[Table("ivy_ask_test_results")] +public class TestRunResultEntity +{ + public Guid Id { get; set; } = Guid.NewGuid(); + + public Guid TestRunId { get; set; } + public TestRunEntity TestRun { get; set; } = null!; + + public Guid QuestionId { get; set; } + public QuestionEntity Question { get; set; } = null!; + + public string ResponseText { get; set; } = ""; + public int ResponseTimeMs { get; set; } + public bool IsSuccess { get; set; } + public int HttpStatus { get; set; } + + [MaxLength(500)] + public string? ErrorMessage { get; set; } + + public DateTime CreatedAt { get; set; } = DateTime.UtcNow; +}