Embed question verification references

This commit is contained in:
hz
2026-07-13 22:29:20 -05:00
parent 0fe47de423
commit 292f8ff9b4
10 changed files with 203 additions and 4 deletions
@@ -323,6 +323,36 @@ public class QuestionsController : ControllerBase
return Ok(new { upserted });
}
[HttpPost("admin/references/bulk")]
[Authorize(Roles = "SUPER")]
public async Task<IActionResult> BulkUpdateReferences([FromBody] BulkQuestionReferencesRequest req)
{
if (req.Questions.Count == 0)
return BadRequest("questions required");
var externalIds = new HashSet<string>(StringComparer.Ordinal);
foreach (var update in req.Questions)
{
if (string.IsNullOrWhiteSpace(update.ExternalId))
return BadRequest("externalId required");
var externalId = update.ExternalId.Trim();
if (!externalIds.Add(externalId))
return BadRequest($"duplicate externalId: {externalId}");
var validation = QuestionValidator.ValidateReferences(update.References, required: true);
if (validation is not null)
return BadRequest($"{externalId}: {validation}");
}
var missing = await _questions.GetMissingExternalIdsAsync(externalIds);
if (missing.Count > 0)
return BadRequest($"unknown externalIds: {string.Join(", ", missing)}");
var updated = await _questions.UpdateReferencesByExternalIdAsync(req.Questions);
if (updated != req.Questions.Count)
return Conflict("one or more questions changed before references could be updated");
return Ok(new { updated });
}
[HttpPut("{id}")]
[Authorize(Roles = "SUPER")]
public async Task<IActionResult> Update(string id, [FromBody] UpsertQuestionRequest req)