Spaces:
Runtime error
Runtime error
| """User entity for authentication.""" | |
| from datetime import datetime | |
| from sqlalchemy import Column, Integer, String, DateTime | |
| from sqlalchemy.orm import relationship | |
| from database import Base | |
| class User(Base): | |
| """Registered user with authentication credentials.""" | |
| __tablename__ = "users_001_todo" | |
| id = Column(Integer, primary_key=True, autoincrement=True) | |
| email = Column(String(255), unique=True, index=True, nullable=False) | |
| password_hash = Column(String(255), nullable=False) # bcrypt hash is ~60 chars | |
| created_at = Column(DateTime, default=datetime.utcnow, nullable=False) | |
| updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False) | |
| # Relationship to todos - enables cascading deletes | |
| todos = relationship("Todo", back_populates="user", cascade="all, delete-orphan") | |
| def __repr__(self) -> str: | |
| return f"<User(id={self.id}, email={self.email})>" | |
| # For Pydantic serialization | |
| def to_dict(self): | |
| return { | |
| "id": self.id, | |
| "email": self.email, | |
| "created_at": self.created_at.isoformat(), | |
| "updated_at": self.updated_at.isoformat(), | |
| } | |