klg-asutk-app/backend/app/schemas/common.py
Yuriy 0150aba4f5 Consolidation: KLG ASUTK + PAPA integration
- Unify API: lib/api.ts uses /api/v1, inbox uses /api/inbox (rewrites)
- Remove localhost refs: openapi, inbox page
- Add rewrites: /api/inbox|tmc -> inbox-server, /api/v1 -> FastAPI
- Add stub routes: knowledge/insights, recommendations, search, log-error
- Transfer from PAPA: prompts (inspection, tmc), scripts, supabase, data/tmc-requests
- Fix inbox-server: ORDER BY created_at, package.json
- Remove redundant app/api/inbox/files route (rewrites handle it)
- knowledge/ in gitignore (large PDFs)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 17:18:31 +03:00

35 lines
973 B
Python

from datetime import datetime
from pydantic import BaseModel, field_validator
class ORMBase(BaseModel):
model_config = {"from_attributes": True}
def _coerce_datetime(v):
"""SQLite может вернуть datetime как str — приводим к datetime."""
if isinstance(v, datetime):
return v
if isinstance(v, str):
s = v.strip()
for fmt in ("%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M:%S.%f"):
try:
return datetime.strptime(s[:26] if fmt.endswith(".%f") else s[:19], fmt)
except (ValueError, TypeError):
continue
try:
return datetime.fromisoformat(s.replace(" ", "T", 1))
except Exception:
pass
return v
class TimestampOut(ORMBase):
created_at: datetime
updated_at: datetime
@field_validator("created_at", "updated_at", mode="before")
@classmethod
def parse_dt(cls, v):
return _coerce_datetime(v)