Add wrong answer follow-up prompts

This commit is contained in:
hz
2026-07-11 02:16:01 -05:00
parent c716b16c53
commit ad6b3863cc
8 changed files with 212 additions and 3 deletions
@@ -220,6 +220,9 @@ public class QuestionsController : ControllerBase
return "explanation required";
if (req.ChoiceSelectionPercentages.Any(entry => entry.Value is < 0 or > 100))
return "choiceSelectionPercentages values must be between 0 and 100";
var followupValidation = ValidateWrongAnswerFollowups(req);
if (followupValidation is not null)
return followupValidation;
if (string.IsNullOrWhiteSpace(req.System))
return "system required";
if (string.IsNullOrWhiteSpace(req.Discipline))
@@ -230,6 +233,28 @@ public class QuestionsController : ControllerBase
return null;
}
private static string? ValidateWrongAnswerFollowups(UpsertQuestionRequest req)
{
var choiceIds = req.Choices.Select(c => c.Id).Where(id => !string.IsNullOrWhiteSpace(id)).ToHashSet();
foreach (var entry in req.WrongAnswerFollowups)
{
if (!choiceIds.Contains(entry.Key))
return "wrongAnswerFollowups keys must match a choice id";
if (entry.Key == req.CorrectChoiceId)
return "wrongAnswerFollowups should only target incorrect choices";
if (string.IsNullOrWhiteSpace(entry.Value.Prompt))
return "wrongAnswerFollowups prompt required";
if (string.IsNullOrWhiteSpace(entry.Value.TeachingPoint))
return "wrongAnswerFollowups teachingPoint required";
if (entry.Value.Choices.Count == 0)
return "wrongAnswerFollowups choices required";
if (!entry.Value.Choices.Any(c => c.Id == entry.Value.CorrectChoiceId))
return "wrongAnswerFollowups correctChoiceId must match a follow-up choice id";
}
return null;
}
private string CurrentUserId() =>
User.FindFirstValue(ClaimTypes.NameIdentifier)
?? User.FindFirstValue(ClaimTypes.Name)