scheduled_drying.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from datetime import datetime
  2. from typing import Annotated
  3. from pydantic import AfterValidator, BaseModel, Field
  4. from backend.app.schemas.print_queue import UTCDatetime
  5. from backend.app.utils.local_time import to_naive_utc
  6. # Coerces any client-sent UTC offset to the naive UTC the DB stores.
  7. NaiveUTCDatetime = Annotated[datetime | None, AfterValidator(to_naive_utc)]
  8. class ScheduledDryingCreate(BaseModel):
  9. printer_id: int
  10. ams_id: int = 0
  11. temp: int = Field(ge=45, le=85)
  12. duration_hours: int = Field(ge=1, le=24)
  13. # max_length matches the String(50) column: without it PostgreSQL 500s on
  14. # an over-long value and SQLite silently accepts it.
  15. filament: str = Field("", max_length=50)
  16. rotate_tray: bool = False
  17. start_after: NaiveUTCDatetime = None
  18. class ScheduledDryingResponse(BaseModel):
  19. id: int
  20. printer_id: int
  21. ams_id: int
  22. temp: int
  23. duration_hours: int
  24. filament: str
  25. rotate_tray: bool
  26. # UTCDatetime, not a bare datetime: every queue route sends the Z suffix and
  27. # the frontend parses these the same way.
  28. start_after: UTCDatetime
  29. status: str
  30. waiting_reason: str | None
  31. error_message: str | None
  32. created_at: UTCDatetime
  33. started_at: UTCDatetime
  34. completed_at: UTCDatetime
  35. model_config = {"from_attributes": True}