
- 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
60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
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)
|