
- Set up project structure with FastAPI and SQLite - Create models for users, questions, and quizzes - Implement Alembic migrations with seed data - Add user authentication with JWT - Implement question management endpoints - Implement quiz creation and management - Add quiz-taking and scoring functionality - Set up API documentation and health check endpoint - Update README with comprehensive documentation
73 lines
2.7 KiB
Python
73 lines
2.7 KiB
Python
from datetime import datetime
|
|
from sqlalchemy import Boolean, Column, DateTime, Enum, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.session import Base
|
|
|
|
|
|
class BibleBook(Base):
|
|
__tablename__ = "bible_books"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, index=True, nullable=False)
|
|
testament = Column(Enum("Old", "New", name="testament_enum"), nullable=False)
|
|
|
|
# Relationships
|
|
questions = relationship("Question", back_populates="bible_book")
|
|
|
|
|
|
class QuestionDifficulty(Base):
|
|
__tablename__ = "question_difficulties"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, unique=True, index=True, nullable=False) # Easy, Medium, Hard
|
|
description = Column(String)
|
|
|
|
# Relationships
|
|
questions = relationship("Question", back_populates="difficulty")
|
|
|
|
|
|
class QuestionCategory(Base):
|
|
__tablename__ = "question_categories"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, unique=True, index=True, nullable=False)
|
|
description = Column(String)
|
|
|
|
# Relationships
|
|
questions = relationship("Question", back_populates="category")
|
|
|
|
|
|
class Question(Base):
|
|
__tablename__ = "questions"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
text = Column(Text, nullable=False)
|
|
bible_reference = Column(String) # Format: Book Chapter:Verse, e.g., "John 3:16"
|
|
explanation = Column(Text)
|
|
bible_book_id = Column(Integer, ForeignKey("bible_books.id"))
|
|
difficulty_id = Column(Integer, ForeignKey("question_difficulties.id"))
|
|
category_id = Column(Integer, ForeignKey("question_categories.id"))
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Relationships
|
|
bible_book = relationship("BibleBook", back_populates="questions")
|
|
difficulty = relationship("QuestionDifficulty", back_populates="questions")
|
|
category = relationship("QuestionCategory", back_populates="questions")
|
|
options = relationship("QuestionOption", back_populates="question", cascade="all, delete-orphan")
|
|
quiz_questions = relationship("QuizQuestion", back_populates="question")
|
|
|
|
|
|
class QuestionOption(Base):
|
|
__tablename__ = "question_options"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
question_id = Column(Integer, ForeignKey("questions.id"), nullable=False)
|
|
text = Column(Text, nullable=False)
|
|
is_correct = Column(Boolean, default=False, nullable=False)
|
|
explanation = Column(Text)
|
|
|
|
# Relationships
|
|
question = relationship("Question", back_populates="options")
|
|
user_answers = relationship("QuizQuestionAnswer", back_populates="selected_option") |