Automated Action 6f0470e475 Implement Bible Quiz App API with FastAPI and SQLite
- 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
2025-06-05 10:31:02 +00:00

29 lines
923 B
Python

from sqlalchemy.orm import Session
from typing import List, Optional
from app.models.result import Result
from app.schemas.result import ResultCreate
def create_result(db: Session, result_data: ResultCreate) -> Result:
"""Create a new quiz result."""
db_result = Result(**result_data.model_dump())
db.add(db_result)
db.commit()
db.refresh(db_result)
return db_result
def get_result(db: Session, result_id: int) -> Optional[Result]:
"""Get a result by ID."""
return db.query(Result).filter(Result.id == result_id).first()
def get_results(db: Session, skip: int = 0, limit: int = 100) -> List[Result]:
"""Get all results with pagination."""
return db.query(Result).offset(skip).limit(limit).all()
def get_user_results(db: Session, user_id: str) -> List[Result]:
"""Get all results for a specific user."""
return db.query(Result).filter(Result.user_id == user_id).all()