- Switched from psycopg2 to asyncpg for async SQLAlchemy support - Fixed router registration in main.py - removed duplicate prefixes - Added user_data export to routers/__init__.py - Refactored decks router to use DeckManager service layer - Integrated FuzzyCardMatcher into card_router search endpoints - Made WishlistCreate.card_id optional for proper schema validation - Set PostgreSQL password and configured scram-sha-256 auth - Updated alembic.ini to use local PostgreSQL instead of Docker hostname - Created generic_schemas.py for reusable schema patterns - Added test_routers.py and test_schema_validation.py test files - All 6 Alembic migrations applied successfully (37 tables created) - Application running on port 8000 with all services connected
109 lines
2.7 KiB
Python
109 lines
2.7 KiB
Python
"""Pydantic schemas for card search and import features."""
|
|
from pydantic import BaseModel, Field, ConfigDict
|
|
from typing import List, Optional, Dict, Any
|
|
from datetime import datetime
|
|
|
|
|
|
# ===== Card Search Schemas =====
|
|
|
|
class CardResponse(BaseModel):
|
|
"""Card response with details."""
|
|
id: int
|
|
name: str
|
|
mana_cost: Optional[str] = None
|
|
type_line: Optional[str] = None
|
|
oracle_text: Optional[str] = None
|
|
power: Optional[str] = None
|
|
toughness: Optional[str] = None
|
|
rarity: Optional[str] = None
|
|
layout: Optional[str] = None
|
|
colors: Optional[str] = None
|
|
set_code: Optional[str] = None
|
|
set_name: Optional[str] = None
|
|
identifiers: Optional[Dict[str, Any]] = None
|
|
images: Optional[Dict[str, Any]] = None
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class SetResponse(BaseModel):
|
|
"""Set response."""
|
|
id: int
|
|
name: str
|
|
code: str
|
|
release_date: Optional[datetime] = None
|
|
card_count: Optional[int] = None
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class CardTypeResponse(BaseModel):
|
|
"""Card type response."""
|
|
type: str
|
|
|
|
|
|
class CardSearchResponse(BaseModel):
|
|
"""Card search response."""
|
|
cards: List[Dict[str, Any]]
|
|
total: int
|
|
page: int
|
|
page_size: int
|
|
total_pages: int
|
|
|
|
|
|
# ===== Card Import Schemas =====
|
|
|
|
class CardImportResponse(BaseModel):
|
|
"""Response after successful card import upload."""
|
|
message: str
|
|
batch_id: int
|
|
card_count: int
|
|
status: str
|
|
imported_at: datetime
|
|
|
|
|
|
class CardImportStatusResponse(BaseModel):
|
|
"""Response showing current import status."""
|
|
has_import: bool
|
|
batch_id: Optional[int] = None
|
|
status: Optional[str] = None
|
|
card_count: Optional[int] = None
|
|
matched_count: Optional[int] = None
|
|
unmatched_count: Optional[int] = None
|
|
last_imported: Optional[datetime] = None
|
|
error_message: Optional[str] = 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', 'high_confidence', 'low_confidence'
|
|
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
|