53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
"""
|
||
Pydantic схемы для Document
|
||
"""
|
||
from uuid import UUID
|
||
from datetime import datetime
|
||
from typing import Any
|
||
from pydantic import BaseModel
|
||
|
||
|
||
class DocumentBase(BaseModel):
|
||
"""Базовая схема документа"""
|
||
title: str
|
||
content: str
|
||
metadata: dict[str, Any] = {}
|
||
|
||
|
||
class DocumentCreate(DocumentBase):
|
||
"""Схема создания документа"""
|
||
collection_id: UUID
|
||
|
||
|
||
class DocumentUpdate(BaseModel):
|
||
"""Схема обновления документа"""
|
||
title: str | None = None
|
||
content: str | None = None
|
||
metadata: dict[str, Any] | None = None
|
||
|
||
|
||
class DocumentResponse(BaseModel):
|
||
"""Схема ответа с документом"""
|
||
document_id: UUID
|
||
collection_id: UUID
|
||
title: str
|
||
content: str
|
||
metadata: dict[str, Any]
|
||
created_at: datetime
|
||
|
||
@classmethod
|
||
def from_entity(cls, document: "Document") -> "DocumentResponse":
|
||
"""Создать из доменной сущности"""
|
||
return cls(
|
||
document_id=document.document_id,
|
||
collection_id=document.collection_id,
|
||
title=document.title,
|
||
content=document.content,
|
||
metadata=document.metadata,
|
||
created_at=document.created_at
|
||
)
|
||
|
||
class Config:
|
||
from_attributes = True
|
||
|