pdf-quiz-generator/backend/app/schemas/flashcard.py
Daniel 9b51a17507 feat: flashcard decks share the question and article category tree
Questions and articles both pointed at `question_categories`; decks had no
category at all, so the three content types could not be filtered together and a
topic's cards were unreachable from its category.

- `flashcard_decks.category_id` references the same tree (migration
  t2f3a4b5c697), so one category now spans questions, articles and cards.
- `GET /flashcards/` takes `category_id` and includes descendants, so a parent
  category picks up everything filed beneath it.
- `PATCH /flashcards/{id}` files or unfiles a deck, refusing a category id that
  does not exist rather than storing a dangling reference.
- The cards page shows each deck's category as a selector.

Tests: 5 new backend (all three types resolve to the same id, descendant
filtering, file and unfile, unknown category refused, renaming leaves the
category alone) and 1 new frontend. Full suites green: 101 backend,
136 frontend, build clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PpfzbZ1QTLMeVYxM2kyq8m
2026-09-10 01:40:03 +02:00

32 lines
754 B
Python

from datetime import datetime
from pydantic import BaseModel
class FlashcardDeckCreate(BaseModel):
model_config = {"protected_namespaces": ()}
section_id: int
title: str
model_id: str | None = None
class FlashcardResponse(BaseModel):
id: int
front: str
back: str
page_reference: int | None = None
image_path: str | None = None
class Config:
from_attributes = True
class FlashcardDeckResponse(BaseModel):
id: int
title: str
section_id: int | None = None
category_id: int | None = None
user_id: int
card_count: int
created_at: datetime
class Config:
from_attributes = True
class FlashcardDeckDetail(FlashcardDeckResponse):
cards: list[FlashcardResponse] = []