trung.le
feat: Establish core backend with user authentication, admin test management, user test taking, and a Dockerfile import fix.
3a81b47 | from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, JSON | |
| from sqlalchemy.orm import relationship | |
| from backend.database import Base | |
| class User(Base): | |
| __tablename__ = "users" | |
| id = Column(Integer, primary_key=True, index=True) | |
| username = Column(String, unique=True, index=True) | |
| email = Column(String, unique=True, index=True) | |
| hashed_password = Column(String) | |
| is_admin = Column(Boolean, default=False) | |
| class Test(Base): | |
| __tablename__ = "tests" | |
| id = Column(Integer, primary_key=True, index=True) | |
| title = Column(String, index=True) | |
| description = Column(String) | |
| created_by = Column(Integer, ForeignKey("users.id")) | |
| questions = relationship("Question", back_populates="test") | |
| class Question(Base): | |
| __tablename__ = "questions" | |
| id = Column(Integer, primary_key=True, index=True) | |
| test_id = Column(Integer, ForeignKey("tests.id")) | |
| question_text = Column(String) | |
| options = Column(JSON) # List of strings | |
| correct_answer = Column(String) | |
| test = relationship("Test", back_populates="questions") | |
| class UserTestResult(Base): | |
| __tablename__ = "user_test_results" | |
| id = Column(Integer, primary_key=True, index=True) | |
| user_id = Column(Integer, ForeignKey("users.id")) | |
| test_id = Column(Integer, ForeignKey("tests.id")) | |
| score = Column(Integer) | |
| answers = Column(JSON) # Map of question_id to selected_option | |