Add synced question bookmarks
This commit is contained in:
@@ -17,6 +17,7 @@ public class QuestionsController : ControllerBase
|
||||
private readonly QuestionMediaStore _media;
|
||||
private readonly AnswerStatisticsStore _statistics;
|
||||
private readonly ServiceMetrics _metrics;
|
||||
private readonly QuestionBookmarkStore _bookmarks;
|
||||
|
||||
public QuestionsController(
|
||||
QuestionStore questions,
|
||||
@@ -24,7 +25,8 @@ public class QuestionsController : ControllerBase
|
||||
RatingStore ratings,
|
||||
QuestionMediaStore media,
|
||||
AnswerStatisticsStore statistics,
|
||||
ServiceMetrics metrics)
|
||||
ServiceMetrics metrics,
|
||||
QuestionBookmarkStore bookmarks)
|
||||
{
|
||||
_questions = questions;
|
||||
_attempts = attempts;
|
||||
@@ -32,6 +34,7 @@ public class QuestionsController : ControllerBase
|
||||
_media = media;
|
||||
_statistics = statistics;
|
||||
_metrics = metrics;
|
||||
_bookmarks = bookmarks;
|
||||
}
|
||||
|
||||
[HttpGet("systems")]
|
||||
@@ -49,14 +52,17 @@ public class QuestionsController : ControllerBase
|
||||
var questions = await _questions.SearchAsync(req, User.IsInRole("SUPER"));
|
||||
var percentages = await _statistics.GetPercentagesByQuestionAsync(questions.Select(q => q.ExternalId));
|
||||
var questionElos = await _ratings.GetQuestionElosAsync(questions.Select(q => q.ExternalId));
|
||||
var bookmarkedIds = await _bookmarks.GetBookmarkedIdsAsync(UserId(), questions.Select(q => q.ExternalId));
|
||||
return Ok(questions.Select(q =>
|
||||
{
|
||||
percentages.TryGetValue(q.ExternalId, out var questionPercentages);
|
||||
return QuestionResponse.FromModel(
|
||||
var response = QuestionResponse.FromModel(
|
||||
q,
|
||||
questionPercentages,
|
||||
questionElos.GetValueOrDefault(q.ExternalId, 1000),
|
||||
req.SupportsChoicePools);
|
||||
response.IsBookmarked = bookmarkedIds.Contains(q.ExternalId);
|
||||
return response;
|
||||
}).ToList());
|
||||
}
|
||||
|
||||
@@ -90,9 +96,16 @@ public class QuestionsController : ControllerBase
|
||||
|
||||
var percentages = await _statistics.GetPercentagesForQuestionAsync(question.ExternalId);
|
||||
var questionElo = await _ratings.GetQuestionEloAsync(question.ExternalId);
|
||||
return Ok(QuestionResponse.FromModel(question, percentages, questionElo));
|
||||
var response = QuestionResponse.FromModel(question, percentages, questionElo);
|
||||
response.IsBookmarked = await _bookmarks.IsBookmarkedAsync(UserId(), question.ExternalId);
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
private string UserId() => User.FindFirstValue(ClaimTypes.NameIdentifier)
|
||||
?? User.FindFirstValue(ClaimTypes.Name)
|
||||
?? User.Identity?.Name
|
||||
?? "";
|
||||
|
||||
[HttpPost("attempts/first")]
|
||||
[Authorize(Roles = "USER,SUPER")]
|
||||
public async Task<IActionResult> RecordFirstAttempt([FromBody] FirstQuestionAttemptRequest req)
|
||||
|
||||
Reference in New Issue
Block a user