Add wrong answer follow-up prompts
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -16,6 +16,7 @@ public class Question
|
||||
public string CorrectChoiceId { get; set; } = "";
|
||||
public string Explanation { get; set; } = "";
|
||||
public Dictionary<string, string> ChoiceExplanations { get; set; } = [];
|
||||
public Dictionary<string, WrongAnswerFollowup> WrongAnswerFollowups { get; set; } = [];
|
||||
public Dictionary<string, int> ChoiceSelectionPercentages { get; set; } = [];
|
||||
public string Discipline { get; set; } = "";
|
||||
public string System { get; set; } = "";
|
||||
@@ -42,3 +43,11 @@ public class QuestionLab
|
||||
public string Unit { get; set; } = "";
|
||||
public string Reference { get; set; } = "";
|
||||
}
|
||||
|
||||
public class WrongAnswerFollowup
|
||||
{
|
||||
public string Prompt { get; set; } = "";
|
||||
public List<QuestionChoice> Choices { get; set; } = [];
|
||||
public string CorrectChoiceId { get; set; } = "";
|
||||
public string TeachingPoint { get; set; } = "";
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public class UpsertQuestionRequest
|
||||
public string CorrectChoiceId { get; set; } = "";
|
||||
public string Explanation { get; set; } = "";
|
||||
public Dictionary<string, string> ChoiceExplanations { get; set; } = [];
|
||||
public Dictionary<string, WrongAnswerFollowup> WrongAnswerFollowups { get; set; } = [];
|
||||
public Dictionary<string, int> ChoiceSelectionPercentages { get; set; } = [];
|
||||
public string Discipline { get; set; } = "";
|
||||
public string System { get; set; } = "";
|
||||
|
||||
@@ -10,6 +10,7 @@ public class QuestionResponse
|
||||
public string CorrectChoiceId { get; set; } = "";
|
||||
public string Explanation { get; set; } = "";
|
||||
public Dictionary<string, string> ChoiceExplanations { get; set; } = [];
|
||||
public Dictionary<string, WrongAnswerFollowup> WrongAnswerFollowups { get; set; } = [];
|
||||
public Dictionary<string, int> ChoiceSelectionPercentages { get; set; } = [];
|
||||
public string Discipline { get; set; } = "";
|
||||
public string System { get; set; } = "";
|
||||
@@ -33,6 +34,7 @@ public class QuestionResponse
|
||||
CorrectChoiceId = question.CorrectChoiceId,
|
||||
Explanation = question.Explanation,
|
||||
ChoiceExplanations = question.ChoiceExplanations,
|
||||
WrongAnswerFollowups = question.WrongAnswerFollowups,
|
||||
ChoiceSelectionPercentages = BuildChoiceSelectionPercentages(question, liveChoiceSelectionPercentages),
|
||||
Discipline = question.Discipline,
|
||||
System = question.System,
|
||||
|
||||
@@ -136,6 +136,7 @@ public class QuestionStore
|
||||
CorrectChoiceId = req.CorrectChoiceId.Trim(),
|
||||
Explanation = req.Explanation.Trim(),
|
||||
ChoiceExplanations = req.ChoiceExplanations,
|
||||
WrongAnswerFollowups = req.WrongAnswerFollowups,
|
||||
ChoiceSelectionPercentages = req.ChoiceSelectionPercentages,
|
||||
Discipline = req.Discipline.Trim(),
|
||||
System = req.System.Trim(),
|
||||
|
||||
Reference in New Issue
Block a user