diff --git a/app/schemas/tag.py b/app/schemas/tag.py new file mode 100644 index 0000000..63d4cd9 --- /dev/null +++ b/app/schemas/tag.py @@ -0,0 +1,57 @@ +"""Pydantic schemas for Tag and TagLink endpoints.""" + +from __future__ import annotations + +from datetime import datetime +from typing import Optional + +from pydantic import BaseModel, ConfigDict, Field + +from app.models.tag_link import TagLinkParentType + + +class TagCreate(BaseModel): + """Body for POST /api/v1/tags/.""" + + name: str = Field(..., min_length=1, max_length=64) + color: str = Field(default="#3B82F6", pattern=r"^#[0-9A-Fa-f]{6}$") + + +class TagOut(BaseModel): + """Response schema for a tag.""" + + model_config = ConfigDict(from_attributes=True) + + id: int + org_id: int + name: str + color: str + created_at: datetime + updated_at: datetime + deleted_at: Optional[datetime] = None + + +class TagLinkCreate(BaseModel): + """Body for POST /api/v1/tags/link.""" + + tag_id: int = Field(..., ge=1) + parent_type: TagLinkParentType + parent_id: int = Field(..., ge=1) + + +class TagLinkOut(BaseModel): + """Response schema for a tag link.""" + + model_config = ConfigDict(from_attributes=True) + + id: int + org_id: int + tag_id: int + parent_type: TagLinkParentType + parent_id: int + created_at: datetime + updated_at: datetime + deleted_at: Optional[datetime] = None + + +__all__ = ["TagCreate", "TagLinkCreate", "TagLinkOut", "TagOut"]