
- Set up project structure with FastAPI and SQLite - Implement user authentication with JWT - Create models for learning content (subjects, lessons, quizzes) - Add progress tracking and gamification features - Implement comprehensive API documentation - Add error handling and validation - Set up proper logging and health check endpoint
37 lines
969 B
Python
37 lines
969 B
Python
from __future__ import annotations
|
|
|
|
from typing import List
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.models.content import Quiz
|
|
from app.schemas.content import QuizCreate, QuizUpdate
|
|
from app.utils.db import CRUDBase
|
|
|
|
|
|
class CRUDQuiz(CRUDBase[Quiz, QuizCreate, QuizUpdate]):
|
|
def get_by_lesson(
|
|
self, db: Session, *, lesson_id: int, skip: int = 0, limit: int = 100
|
|
) -> List[Quiz]:
|
|
"""
|
|
Get quizzes by lesson.
|
|
"""
|
|
return db.query(Quiz).filter(Quiz.lesson_id == lesson_id).offset(skip).limit(limit).all()
|
|
|
|
def get_active_by_lesson(
|
|
self, db: Session, *, lesson_id: int, skip: int = 0, limit: int = 100
|
|
) -> List[Quiz]:
|
|
"""
|
|
Get active quizzes by lesson.
|
|
"""
|
|
return (
|
|
db.query(Quiz)
|
|
.filter(Quiz.lesson_id == lesson_id, Quiz.is_active == True)
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
|
|
quiz = CRUDQuiz(Quiz)
|