feat: add card import feature with fuzzy matching
- Add UserCardImport model (stores imported card names as JSON) - Create card_import_schemas.py with request/response models - Create card_import.py router with import/get/delete endpoints - Add Alembic migration 004 (user_card_imports table) - Fuzzy matching for card name matching (60% threshold) - Integration with deckbuilding via imported cards - Endpoints: GET /api/v1/card-import/status, POST /, DELETE /, GET /summary
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
Pydantic schemas for card import feature.
|
||||
|
||||
Provides request/response models for importing card collections
|
||||
and using them for deckbuilding.
|
||||
"""
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import List, Optional, Dict, Any
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class CardImportRequest(BaseModel):
|
||||
"""Request body for importing card collection."""
|
||||
card_names: List[str] = Field(
|
||||
...,
|
||||
min_length=1,
|
||||
max_length=10000,
|
||||
description="List of card names to import",
|
||||
examples=[["Lightning Bolt", "Shock", "Thoughtseize"]]
|
||||
)
|
||||
|
||||
|
||||
class CardImportResponse(BaseModel):
|
||||
"""Response after successful card import."""
|
||||
message: str
|
||||
card_count: int
|
||||
card_names: List[str]
|
||||
imported_at: datetime
|
||||
|
||||
|
||||
class CardImportStatusResponse(BaseModel):
|
||||
"""Response showing current import status."""
|
||||
has_import: bool
|
||||
card_count: Optional[int] = None
|
||||
card_names: Optional[List[str]] = None
|
||||
last_imported: Optional[datetime] = None
|
||||
|
||||
|
||||
class CardMatchResult(BaseModel):
|
||||
"""Result of matching imported card name to database card."""
|
||||
card_id: Optional[int] = None
|
||||
card_name: str
|
||||
matched_name: str
|
||||
match_type: str # 'exact', 'fuzzy', 'partial'
|
||||
confidence: float # 0.0 to 1.0
|
||||
|
||||
|
||||
class CardImportSummary(BaseModel):
|
||||
"""Summary of card import with match results."""
|
||||
total_cards: int
|
||||
matched_cards: List[CardMatchResult]
|
||||
unmatched_cards: List[str]
|
||||
import_id: Optional[int] = None
|
||||
|
||||
|
||||
# Generic response models
|
||||
class MessageResponse(BaseModel):
|
||||
"""Generic message response."""
|
||||
message: str
|
||||
|
||||
|
||||
class CountResponse(BaseModel):
|
||||
"""Generic count response."""
|
||||
count: int
|
||||
|
||||
|
||||
class ErrorResponse(BaseModel):
|
||||
"""Error response with details."""
|
||||
detail: str
|
||||
error_code: Optional[str] = None
|
||||
Reference in New Issue
Block a user