Embed question verification references
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user