
- Setup project structure and FastAPI application - Configure SQLite database with SQLAlchemy ORM - Setup Alembic for database migrations - Implement user authentication with JWT - Create task models and CRUD operations - Implement task assignment functionality - Add detailed API documentation - Create comprehensive README with usage instructions - Lint code with Ruff
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
from datetime import datetime
|
|
from enum import Enum as PyEnum
|
|
|
|
from sqlalchemy import (
|
|
Boolean,
|
|
Column,
|
|
DateTime,
|
|
Enum,
|
|
ForeignKey,
|
|
Integer,
|
|
String,
|
|
Table,
|
|
Text,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class TaskStatus(str, PyEnum):
|
|
TODO = "todo"
|
|
IN_PROGRESS = "in_progress"
|
|
COMPLETED = "completed"
|
|
CANCELLED = "cancelled"
|
|
|
|
|
|
class TaskPriority(str, PyEnum):
|
|
LOW = "low"
|
|
MEDIUM = "medium"
|
|
HIGH = "high"
|
|
URGENT = "urgent"
|
|
|
|
|
|
# Association table for task assignments
|
|
task_assignments = Table(
|
|
"task_assignments",
|
|
Base.metadata,
|
|
Column("task_id", Integer, ForeignKey("tasks.id"), primary_key=True),
|
|
Column("user_id", Integer, ForeignKey("users.id"), primary_key=True),
|
|
Column("assigned_at", DateTime, default=datetime.utcnow),
|
|
)
|
|
|
|
|
|
class Task(Base):
|
|
__tablename__ = "tasks"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
title = Column(String(255), nullable=False, index=True)
|
|
description = Column(Text, nullable=True)
|
|
status = Column(Enum(TaskStatus), default=TaskStatus.TODO, nullable=False)
|
|
priority = Column(Enum(TaskPriority), default=TaskPriority.MEDIUM, nullable=False)
|
|
due_date = Column(DateTime, nullable=True)
|
|
owner_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
is_deleted = Column(Boolean, default=False)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
completed_at = Column(DateTime, nullable=True)
|
|
|
|
# Relationships
|
|
owner = relationship("User", back_populates="tasks")
|
|
assignees = relationship("User",
|
|
secondary="task_assignments",
|
|
back_populates="assigned_tasks")
|
|
|
|
def __repr__(self):
|
|
return f"<Task {self.title} ({self.status})>"
|