
- Added TodoBoard model and BoardStatus enum
- Created migration for todo boards
- Added TodoBoard API endpoints
- Added board-related features to the README
🤖 Generated with BackendIM... (backend.im)
88 lines
3.1 KiB
Python
88 lines
3.1 KiB
Python
from sqlalchemy import Boolean, Column, Integer, String, Text, DateTime, Enum, Table, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
import enum
|
|
|
|
from .database import Base
|
|
|
|
# Association table for the many-to-many relationship between Todo and Tag
|
|
todo_tag = Table(
|
|
"todo_tag",
|
|
Base.metadata,
|
|
Column("todo_id", Integer, ForeignKey("todos.id"), primary_key=True),
|
|
Column("tag_id", Integer, ForeignKey("tags.id"), primary_key=True)
|
|
)
|
|
|
|
class PriorityLevel(str, enum.Enum):
|
|
LOW = "low"
|
|
MEDIUM = "medium"
|
|
HIGH = "high"
|
|
|
|
class BoardStatus(str, enum.Enum):
|
|
TODO = "todo"
|
|
IN_PROGRESS = "in_progress"
|
|
REVIEW = "review"
|
|
DONE = "done"
|
|
|
|
class Tag(Base):
|
|
__tablename__ = "tags"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String(50), nullable=False, unique=True, index=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
# Relationship to todos
|
|
todos = relationship("Todo", secondary=todo_tag, back_populates="tags")
|
|
|
|
class Subtask(Base):
|
|
__tablename__ = "subtasks"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String(100), nullable=False)
|
|
completed = Column(Boolean, default=False)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Foreign key relationship
|
|
todo_id = Column(Integer, ForeignKey("todos.id", ondelete="CASCADE"), nullable=False)
|
|
|
|
# Relationship to parent todo
|
|
todo = relationship("Todo", back_populates="subtasks")
|
|
|
|
class TodoBoard(Base):
|
|
__tablename__ = "todo_boards"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String(100), nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Relationship to todos
|
|
todos = relationship("Todo", back_populates="board", cascade="all, delete-orphan")
|
|
|
|
class Todo(Base):
|
|
__tablename__ = "todos"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String(100), nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
completed = Column(Boolean, default=False)
|
|
priority = Column(Enum(PriorityLevel), default=PriorityLevel.MEDIUM)
|
|
due_date = Column(DateTime(timezone=True), nullable=True)
|
|
remind_at = Column(DateTime(timezone=True), nullable=True)
|
|
status = Column(Enum(BoardStatus), default=BoardStatus.TODO)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Foreign key relationship to board
|
|
board_id = Column(Integer, ForeignKey("todo_boards.id"), nullable=True)
|
|
|
|
# Relationship to board
|
|
board = relationship("TodoBoard", back_populates="todos")
|
|
|
|
# Relationship to tags
|
|
tags = relationship("Tag", secondary=todo_tag, back_populates="todos")
|
|
|
|
# Relationship to subtasks
|
|
subtasks = relationship("Subtask", back_populates="todo", cascade="all, delete-orphan") |