Add variable question distractor pools
This commit is contained in:
@@ -50,6 +50,32 @@ public class QuestionStore
|
||||
public async Task<Question?> GetByExternalIdAsync(string externalId) =>
|
||||
await _col.Find(q => q.ExternalId == externalId).FirstOrDefaultAsync();
|
||||
|
||||
public async Task<List<Question>> GetAllAsync() =>
|
||||
await _col.Find(Builders<Question>.Filter.Empty).ToListAsync();
|
||||
|
||||
public async Task<(List<Question> Items, string? NextCursor, bool HasMore)> ExportPageAsync(
|
||||
string? after,
|
||||
int requestedLimit)
|
||||
{
|
||||
var limit = Math.Clamp(requestedLimit, 1, 200);
|
||||
var filter = Builders<Question>.Filter.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(after))
|
||||
{
|
||||
if (!ObjectId.TryParse(after, out var cursor))
|
||||
throw new ArgumentException("after must be a valid question cursor", nameof(after));
|
||||
filter = new BsonDocument("_id", new BsonDocument("$gt", cursor));
|
||||
}
|
||||
|
||||
var page = await _col.Find(filter)
|
||||
.Sort(Builders<Question>.Sort.Ascending("_id"))
|
||||
.Limit(limit + 1)
|
||||
.ToListAsync();
|
||||
var hasMore = page.Count > limit;
|
||||
if (hasMore)
|
||||
page.RemoveAt(page.Count - 1);
|
||||
return (page, hasMore ? page[^1].Id : null, hasMore);
|
||||
}
|
||||
|
||||
public async Task<Question?> CreateAsync(UpsertQuestionRequest req)
|
||||
{
|
||||
var question = FromRequest(req);
|
||||
|
||||
Reference in New Issue
Block a user