Add system (curated) vs. user-uploaded flashcards
System decks/notes are owned by a reserved sentinel user id, reusing all existing per-user store/index plumbing unchanged. Regular users see them under a separate "Official Decks" section, can study them with fully independent per-user FSRS progress (lazily materialized on first visit), but can never edit or archive them - enforced both in the client (no Edit/Archive controls) and server-side (ownership guard on every mutating endpoint). Includes a small idempotent seed command (`dotnet run -- seed-flashcards`) for testing, since there's no in-app authoring UI yet.
This commit is contained in:
@@ -33,6 +33,21 @@ public sealed class FlashcardDeckStore
|
||||
public async Task<FlashcardDeck?> GetAsync(string userId, string deckId) =>
|
||||
await _decks.Find(v => v.UserId == userId && v.Id == deckId).FirstOrDefaultAsync();
|
||||
|
||||
// Read-only: the caller's own decks plus every system (shared, admin-curated) deck. Never
|
||||
// used to back a write path - mutations must stay strictly own-user via ListAsync/GetAsync.
|
||||
public Task<List<FlashcardDeck>> ListVisibleAsync(string userId) =>
|
||||
_decks.Find(v => (v.UserId == userId || v.UserId == FlashcardOwners.System) && v.ArchivedUtc == null)
|
||||
.SortBy(v => v.Name).ToListAsync();
|
||||
|
||||
public async Task<FlashcardDeck?> GetVisibleAsync(string userId, string deckId) =>
|
||||
await _decks.Find(v => (v.UserId == userId || v.UserId == FlashcardOwners.System) && v.Id == deckId)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
// No owner filter at all - used only by the controller's mutation guard to check IsSystem
|
||||
// regardless of who's asking.
|
||||
public async Task<FlashcardDeck?> GetAnyAsync(string deckId) =>
|
||||
await _decks.Find(v => v.Id == deckId).FirstOrDefaultAsync();
|
||||
|
||||
public async Task<FlashcardDeck> GetOrCreateDefaultDeckAsync(string userId)
|
||||
{
|
||||
var existing = await _decks.Find(v => v.UserId == userId && v.IsDefault).FirstOrDefaultAsync();
|
||||
|
||||
Reference in New Issue
Block a user