Add study session goals and summaries

This commit is contained in:
hz
2026-08-01 02:34:58 -05:00
parent ddc36a8048
commit 2bd2628009
27 changed files with 926 additions and 21 deletions
@@ -16,7 +16,8 @@ public sealed class ReviewQueueController(
RatingStore ratings,
QuestionBookmarkStore bookmarks,
CreditStore credits,
MasteryAwardService masteryAwards) : ControllerBase
MasteryAwardService masteryAwards,
StudySessionStore studySessions) : ControllerBase
{
[HttpPost("next")]
public async Task<IActionResult> Next([FromBody] ReviewQueueNextRequest req)
@@ -85,9 +86,10 @@ public sealed class ReviewQueueController(
req.DurationSeconds);
if (result is null) return Conflict("review cycle is no longer active");
var awards = new List<CreditAward>();
var delayed = false;
if (result.Attempt.IsCorrect)
{
var delayed = result.Item is not null
delayed = result.Item is not null
&& result.Attempt.CreatedUtc - result.Item.CreatedUtc >= TimeSpan.FromHours(24);
var award = await credits.AwardAsync(userId, new CreditAwardRequest(
$"review:{result.Attempt.Id}", CreditEconomy.ReviewAmount(delayed),
@@ -97,6 +99,14 @@ public sealed class ReviewQueueController(
if (award.Award is not null) awards.Add(award.Award);
}
awards.AddRange(await masteryAwards.AwardPromotionsAsync(userId));
StudySessionEnvelope? studySession = null;
if (!string.IsNullOrWhiteSpace(req.StudySessionId))
studySession = await studySessions.RecordReviewAsync(
req.StudySessionId, userId, result.Attempt, delayed, awards);
if (studySession?.Summary is not null)
awards.AddRange(studySession.Summary.CoinAwards.Where(value =>
value.ReasonCode == CreditReasonCodes.SessionGoalComplete
&& awards.All(existing => existing.ReasonCode != value.ReasonCode)));
return Ok(new ReviewQueueAttemptResponse
{
QuestionExternalId = question.ExternalId,
@@ -104,7 +114,9 @@ public sealed class ReviewQueueController(
QueueState = result.Item?.State ?? ReviewQueueStates.Pending,
PendingCount = checked((int)await queue.CountPendingAsync(userId)),
Credits = await credits.GetStatusAsync(userId),
CreditAwards = awards
CreditAwards = awards,
StudySessionProgress = studySession?.Progress,
SessionSummary = studySession?.Summary
});
}