forked from mtusi2026/mtusi2026lab4
собранная версия, без проверки тестов
This commit is contained in:
+43
-5
@@ -1,10 +1,11 @@
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional, List
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
from pydantic import BaseModel, Field, field_validator, ConfigDict
|
||||
import re
|
||||
|
||||
|
||||
class CreateUserRequest(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
username: str = Field(..., min_length=3, max_length=32)
|
||||
display_name: str = Field(..., min_length=1, max_length=100)
|
||||
password: str = Field(..., min_length=12, max_length=128)
|
||||
@@ -32,6 +33,8 @@ class CreateUserRequest(BaseModel):
|
||||
|
||||
|
||||
class CreateChatRequest(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
title: str = Field(..., min_length=1, max_length=100)
|
||||
member_ids: List[str] = Field(..., min_length=1, max_length=100)
|
||||
|
||||
@@ -44,15 +47,25 @@ class CreateChatRequest(BaseModel):
|
||||
|
||||
|
||||
class CreateMessageRequest(BaseModel):
|
||||
text: str = Field(..., min_length=1, max_length=4000)
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
text: str = Field(..., max_length=4000)
|
||||
attachment_ids: List[str] = Field(default_factory=list, max_length=10)
|
||||
|
||||
@field_validator('text')
|
||||
@classmethod
|
||||
def validate_text(cls, v):
|
||||
if not v.strip():
|
||||
if not v.strip() and not v == '':
|
||||
raise ValueError('text не может состоять только из пробелов')
|
||||
return v
|
||||
|
||||
@field_validator('attachment_ids')
|
||||
@classmethod
|
||||
def validate_attachment_ids(cls, v):
|
||||
if len(v) != len(set(v)):
|
||||
raise ValueError('attachment_ids должны быть уникальными')
|
||||
return v
|
||||
|
||||
|
||||
class UserResponse(BaseModel):
|
||||
id: str
|
||||
@@ -74,6 +87,7 @@ class MessageResponse(BaseModel):
|
||||
sender_id: str
|
||||
text: str
|
||||
created_at: str
|
||||
attachment_ids: List[str] = Field(default_factory=list)
|
||||
|
||||
|
||||
class ChatPage(BaseModel):
|
||||
@@ -94,4 +108,28 @@ class SessionResponse(BaseModel):
|
||||
|
||||
|
||||
class HealthResponse(BaseModel):
|
||||
status: str = "ok"
|
||||
status: str = "ok"
|
||||
|
||||
|
||||
class AttachmentVariant(BaseModel):
|
||||
name: str
|
||||
content_type: str
|
||||
size_bytes: int
|
||||
width: int
|
||||
height: int
|
||||
sha256: str
|
||||
|
||||
|
||||
class AttachmentResponse(BaseModel):
|
||||
id: str
|
||||
chat_id: str
|
||||
owner_id: str
|
||||
filename: str
|
||||
content_type: str
|
||||
size_bytes: int
|
||||
sha256: str
|
||||
status: str
|
||||
variants: List[AttachmentVariant]
|
||||
error_code: Optional[str]
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
Reference in New Issue
Block a user