|
| 1 | +--- |
| 2 | +description: |
| 3 | +globs: |
| 4 | +alwaysApply: true |
| 5 | +--- |
| 6 | +# Card and Review Event Management |
| 7 | + |
| 8 | +This rule details the server actions for managing cards and review events, primarily located in `[app/actions/cards.ts](mdc:app/actions/cards.ts)`, and their associated data structures defined in `[app/types.ts](mdc:app/types.ts)`. |
| 9 | + |
| 10 | +## Core Card Operations |
| 11 | + |
| 12 | +- **Creation**: `createCardAction` adds a new card to a specified deck. |
| 13 | + - Input: `deckId`, `frontText`, `backText`, `token`. |
| 14 | + - Output: `CreateCardResult` with the created `Card`. |
| 15 | +- **Fetching Single Card**: `getCardAction` retrieves a specific card by its ID. |
| 16 | + - Input: `cardId`, `token`. |
| 17 | + - Output: `FetchCardResult` with the `Card`. |
| 18 | +- **Fetching Deck Cards**: `fetchDeckCardsAction` retrieves all cards belonging to a specific deck. |
| 19 | + - Input: `deckId`. |
| 20 | + - Output: `FetchCardsResult` with an array of `Card`s. |
| 21 | +- **Updating**: `updateCardAction` modifies the front or back text of an existing card. |
| 22 | + - Input: `cardId`, `deckId`, `frontText?`, `backText?`, `token`. |
| 23 | + - Output: `UpdateCardResult` with the updated `Card`. |
| 24 | +- **Deletion**: `deleteCardAction` removes a card and its associated review events. |
| 25 | + - Input: `cardId`, `deckId`, `token`. |
| 26 | + - Output: `DeleteCardResult`. |
| 27 | + |
| 28 | +## Card Review and Retrieval |
| 29 | + |
| 30 | +- **Fetching Cards for Review**: `getCardsForReviewAction` retrieves cards for a review session. |
| 31 | + - Supports fetching from specific deck(s) or all decks. |
| 32 | + - Strategies: `random`, `missedFirst`. |
| 33 | + - Input: `GetCardsForReviewParams` (token, deckId?, deckIds?, limit, strategy). |
| 34 | + - Output: `FetchReviewCardsResult` with an array of `Card`s. |
| 35 | +- **Fetching Missed Cards**: `getMissedCardsForDeckInTimeframeAction` retrieves cards from a specific deck that were marked "MISSED" within a given timeframe. |
| 36 | + - Input: `token`, `deckId`, `timeframeDays`. |
| 37 | + - Output: `FetchMissedCardsResult` with an array of `Card`s. |
| 38 | + - Logic: Fetches all card IDs for the deck, then queries `review_events` for "MISSED" events associated with those card IDs within the timeframe. |
| 39 | + |
| 40 | +## Review Event Logging |
| 41 | + |
| 42 | +- **Creating Review Event**: `createReviewEventAction` records the result of a card review. |
| 43 | + - Input: `cardId`, `deckId`, `result` (enum `ReviewResult`). |
| 44 | + - Output: `CreateReviewEventResult` with the ID of the new review event. |
| 45 | + |
| 46 | +## Data Structures (`[app/types.ts](mdc:app/types.ts)`) |
| 47 | + |
| 48 | +- **`Card`**: Client-facing card structure with `id: string`. |
| 49 | + ```typescript |
| 50 | + export interface Card { |
| 51 | + id: string; |
| 52 | + deck_id: string; |
| 53 | + front_text: string; |
| 54 | + back_text: string; |
| 55 | + createdAt?: Date; |
| 56 | + updatedAt?: Date; |
| 57 | + } |
| 58 | + ``` |
| 59 | +- **`CardDocument`**: MongoDB structure for cards with `_id: ObjectId` and `deck_id: ObjectId`. |
| 60 | +- **`ReviewResult`**: Enum for review outcomes (`EASY`, `MEDIUM`, `HARD`, `MISSED`). |
| 61 | + ```typescript |
| 62 | + export enum ReviewResult { |
| 63 | + EASY = "easy", |
| 64 | + MEDIUM = "medium", |
| 65 | + HARD = "hard", |
| 66 | + MISSED = "missed", |
| 67 | + } |
| 68 | + ``` |
| 69 | +- **`ReviewEvent`**: Client-facing review event structure with `id: string`. |
| 70 | + ```typescript |
| 71 | + export interface ReviewEvent { |
| 72 | + id: string; |
| 73 | + card_id: string; |
| 74 | + result: ReviewResult; |
| 75 | + timestamp: Date; |
| 76 | + } |
| 77 | + ``` |
| 78 | +- **`ReviewEventDocument`**: MongoDB structure for review events with `_id: ObjectId` and `card_id: ObjectId`. |
| 79 | + |
| 80 | +## Helper Functions |
| 81 | + |
| 82 | +- `mapCardDocument` (in `[app/actions/cards.ts](mdc:app/actions/cards.ts)`): Converts `CardDocument` (from MongoDB) to `Card` (client-facing), mapping `_id` to `id` and `deck_id` to a string. |
0 commit comments