53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
"""Schemas para TicketIssue"""
|
|
from pydantic import BaseModel, field_validator
|
|
from typing import Optional, List
|
|
from datetime import datetime
|
|
import uuid
|
|
|
|
|
|
class TaggedUserBasic(BaseModel):
|
|
id: uuid.UUID
|
|
full_name: str
|
|
email: str
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class IssueCreate(BaseModel):
|
|
content: str
|
|
priority: str = "MEDIUM"
|
|
tagged_user_ids: List[uuid.UUID] = []
|
|
|
|
@field_validator("priority")
|
|
@classmethod
|
|
def validate_priority(cls, v: str) -> str:
|
|
valid = {"LOW", "MEDIUM", "HIGH", "URGENT"}
|
|
if v.upper() not in valid:
|
|
raise ValueError(f"priority debe ser uno de: {valid}")
|
|
return v.upper()
|
|
|
|
@field_validator("content")
|
|
@classmethod
|
|
def validate_content(cls, v: str) -> str:
|
|
if not v.strip():
|
|
raise ValueError("content no puede estar vacío")
|
|
return v.strip()
|
|
|
|
|
|
class IssueResponse(BaseModel):
|
|
id: uuid.UUID
|
|
ticket_id: uuid.UUID
|
|
tenant_id: uuid.UUID
|
|
content: str
|
|
priority: str
|
|
created_by: uuid.UUID
|
|
created_by_name: str
|
|
tagged_users: List[TaggedUserBasic] = []
|
|
attachment_filename: Optional[str] = None
|
|
attachment_mime_type: Optional[str] = None
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True |