from __future__ import annotations from typing import List from sqlalchemy.orm import Session from app.models.content import DifficultyLevel, Lesson from app.schemas.content import LessonCreate, LessonUpdate from app.utils.db import CRUDBase class CRUDLesson(CRUDBase[Lesson, LessonCreate, LessonUpdate]): def get_by_subject( self, db: Session, *, subject_id: int, skip: int = 0, limit: int = 100 ) -> List[Lesson]: """ Get lessons by subject. """ return ( db.query(Lesson) .filter(Lesson.subject_id == subject_id) .order_by(Lesson.order) .offset(skip) .limit(limit) .all() ) def get_active_by_subject( self, db: Session, *, subject_id: int, skip: int = 0, limit: int = 100 ) -> List[Lesson]: """ Get active lessons by subject. """ return ( db.query(Lesson) .filter(Lesson.subject_id == subject_id, Lesson.is_active == True) .order_by(Lesson.order) .offset(skip) .limit(limit) .all() ) def get_by_difficulty( self, db: Session, *, difficulty: DifficultyLevel, skip: int = 0, limit: int = 100 ) -> List[Lesson]: """ Get lessons by difficulty. """ return ( db.query(Lesson) .filter(Lesson.difficulty == difficulty, Lesson.is_active == True) .order_by(Lesson.order) .offset(skip) .limit(limit) .all() ) lesson = CRUDLesson(Lesson)