74 lines
1.7 KiB
Python
74 lines
1.7 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
from typing import List, Optional
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
|
|
class UserOut(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
id: uuid.UUID
|
|
username: str
|
|
display_name: str
|
|
created_at: datetime
|
|
|
|
|
|
class CreateUser(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
username: str = Field(pattern=r"^[a-z0-9_]{3,32}$")
|
|
display_name: str = Field(min_length=1, max_length=100)
|
|
password: str = Field(min_length=12, max_length=128)
|
|
|
|
|
|
class SessionOut(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
token: str
|
|
token_type: str = "Bearer"
|
|
expires_at: datetime
|
|
user: UserOut
|
|
|
|
|
|
class ChatOut(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
id: uuid.UUID
|
|
title: str
|
|
member_ids: List[uuid.UUID]
|
|
created_at: datetime
|
|
|
|
|
|
class CreateChat(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
title: str = Field(min_length=1, max_length=100)
|
|
member_ids: List[uuid.UUID] = Field(min_length=1, max_length=100)
|
|
|
|
|
|
class MessageOut(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
id: uuid.UUID
|
|
chat_id: uuid.UUID
|
|
sender_id: uuid.UUID
|
|
text: str
|
|
created_at: datetime
|
|
|
|
|
|
class CreateMessage(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
text: str = Field(min_length=1, max_length=4000)
|
|
|
|
|
|
class ChatPage(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
items: List[ChatOut]
|
|
next_cursor: Optional[str]
|
|
|
|
|
|
class MessagePage(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
items: List[MessageOut]
|
|
next_cursor: Optional[str]
|
|
|
|
|
|
class Health(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
status: str = "ok"
|