
- Setup project structure with FastAPI app - Create SQLAlchemy models for categories, questions, quizzes, and results - Implement API endpoints for all CRUD operations - Set up Alembic migrations for database schema management - Add comprehensive documentation in README.md
24 lines
832 B
Python
24 lines
832 B
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
|
|
class ResultBase(BaseModel):
|
|
user_id: str = Field(..., min_length=1, max_length=100, description="User ID")
|
|
quiz_id: int = Field(..., description="ID of the quiz taken")
|
|
score: float = Field(..., ge=0, le=100, description="Percentage score (0-100)")
|
|
total_questions: int = Field(..., gt=0, description="Total number of questions in the quiz")
|
|
correct_answers: int = Field(..., ge=0, description="Number of questions answered correctly")
|
|
time_taken: Optional[float] = Field(None, ge=0, description="Time taken to complete the quiz in seconds")
|
|
|
|
|
|
class ResultCreate(ResultBase):
|
|
pass
|
|
|
|
|
|
class ResultResponse(ResultBase):
|
|
id: int
|
|
completed_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True |