## Summary Implements Phase 2.5 Step Library Foundation: ### Issues Completed - #3 User Preferences - export format default setting - #5 Step Categories - database table and seed data - #6 Step Library - database schema and migrations - #7 Step Library - CRUD API endpoints - #8 Step Library - rating and review system ### Changes **Backend:** - Migration 007: step_categories table with 10 seeded global categories - Migration 008: step_library, step_ratings, step_usage_log tables - Full CRUD API for step categories (/api/v1/step-categories) - Full CRUD API for step library (/api/v1/steps) with search, filters, ratings - CORS support for Railway PR environments (ALLOW_RAILWAY_ORIGINS) **Frontend:** - User preferences store (Zustand + localStorage) - Settings page at /settings with export format dropdown - Default export format applied in SessionDetailPage ### Testing - Tested in Railway PR environment - Database seeded with 7 MSP troubleshooting trees - All API endpoints verified working
65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
import uuid
|
|
from datetime import datetime, timezone
|
|
from typing import Optional, TYPE_CHECKING
|
|
from sqlalchemy import String, Text, DateTime, ForeignKey, Boolean, Integer, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from app.core.database import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.team import Team
|
|
from app.models.user import User
|
|
|
|
|
|
class StepCategory(Base):
|
|
"""Admin-managed categories for organizing step library entries.
|
|
|
|
Categories can be:
|
|
- Global (team_id=NULL): Created by Patherly admins, visible to all
|
|
- Team-specific (team_id set): Created by team admins, visible to team members
|
|
"""
|
|
__tablename__ = "step_categories"
|
|
__table_args__ = (
|
|
UniqueConstraint('slug', 'team_id', name='uq_step_categories_slug_team'),
|
|
)
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True),
|
|
primary_key=True,
|
|
default=uuid.uuid4
|
|
)
|
|
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
|
slug: Mapped[str] = mapped_column(String(100), nullable=False, index=True)
|
|
description: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
team_id: Mapped[Optional[uuid.UUID]] = mapped_column(
|
|
UUID(as_uuid=True),
|
|
ForeignKey("teams.id", ondelete="CASCADE"),
|
|
nullable=True,
|
|
index=True
|
|
)
|
|
display_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0, index=True)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
|
created_by: Mapped[Optional[uuid.UUID]] = mapped_column(
|
|
UUID(as_uuid=True),
|
|
ForeignKey("users.id", ondelete="SET NULL"),
|
|
nullable=True
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
default=lambda: datetime.now(timezone.utc)
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
default=lambda: datetime.now(timezone.utc),
|
|
onupdate=lambda: datetime.now(timezone.utc)
|
|
)
|
|
|
|
# Relationships
|
|
team: Mapped[Optional["Team"]] = relationship("Team", back_populates="step_categories")
|
|
creator: Mapped[Optional["User"]] = relationship("User", foreign_keys=[created_by])
|
|
|
|
@property
|
|
def is_global(self) -> bool:
|
|
"""Returns True if this is a global category (not team-specific)."""
|
|
return self.team_id is None
|