forked from mtusi2026/mtusi2026lab4
Подгрузка всех рабочих файлов из lab3
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional, List
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
import re
|
||||
|
||||
|
||||
class CreateUserRequest(BaseModel):
|
||||
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)
|
||||
|
||||
@field_validator('username')
|
||||
@classmethod
|
||||
def validate_username(cls, v):
|
||||
if not re.match(r'^[a-z0-9_]{3,32}$', v):
|
||||
raise ValueError('username должен содержать только a-z, 0-9, _ (3-32 символа)')
|
||||
return v
|
||||
|
||||
@field_validator('display_name')
|
||||
@classmethod
|
||||
def validate_display_name(cls, v):
|
||||
if not v.strip():
|
||||
raise ValueError('display_name не может состоять только из пробелов')
|
||||
return v
|
||||
|
||||
@field_validator('password')
|
||||
@classmethod
|
||||
def validate_password(cls, v):
|
||||
if not v.strip():
|
||||
raise ValueError('password не может состоять только из пробелов')
|
||||
return v
|
||||
|
||||
|
||||
class CreateChatRequest(BaseModel):
|
||||
title: str = Field(..., min_length=1, max_length=100)
|
||||
member_ids: List[str] = Field(..., min_length=1, max_length=100)
|
||||
|
||||
@field_validator('title')
|
||||
@classmethod
|
||||
def validate_title(cls, v):
|
||||
if not v.strip():
|
||||
raise ValueError('title не может состоять только из пробелов')
|
||||
return v
|
||||
|
||||
|
||||
class CreateMessageRequest(BaseModel):
|
||||
text: str = Field(..., min_length=1, max_length=4000)
|
||||
|
||||
@field_validator('text')
|
||||
@classmethod
|
||||
def validate_text(cls, v):
|
||||
if not v.strip():
|
||||
raise ValueError('text не может состоять только из пробелов')
|
||||
return v
|
||||
|
||||
|
||||
class UserResponse(BaseModel):
|
||||
id: str
|
||||
username: str
|
||||
display_name: str
|
||||
created_at: str
|
||||
|
||||
|
||||
class ChatResponse(BaseModel):
|
||||
id: str
|
||||
title: str
|
||||
member_ids: List[str]
|
||||
created_at: str
|
||||
|
||||
|
||||
class MessageResponse(BaseModel):
|
||||
id: str
|
||||
chat_id: str
|
||||
sender_id: str
|
||||
text: str
|
||||
created_at: str
|
||||
|
||||
|
||||
class ChatPage(BaseModel):
|
||||
items: List[ChatResponse]
|
||||
next_cursor: Optional[str] = None
|
||||
|
||||
|
||||
class MessagePage(BaseModel):
|
||||
items: List[MessageResponse]
|
||||
next_cursor: Optional[str] = None
|
||||
|
||||
|
||||
class SessionResponse(BaseModel):
|
||||
token: str
|
||||
token_type: str = "Bearer"
|
||||
expires_at: str
|
||||
user: UserResponse
|
||||
|
||||
|
||||
class HealthResponse(BaseModel):
|
||||
status: str = "ok"
|
||||
Reference in New Issue
Block a user