feat: update API models for lab2

This commit is contained in:
sinveria
2026-11-04 17:49:52 +03:00
parent 23d16a1cc3
commit 37bebacc14
+16 -8
View File
@@ -1,3 +1,4 @@
from datetime import datetime, timezone
from typing import List, Optional
@@ -6,12 +7,13 @@ from pydantic import BaseModel, ConfigDict, Field, field_validator
class BaseConfig(BaseModel):
model_config = ConfigDict(
from_attributes=True,
json_encoders={
datetime: lambda value: value.astimezone(timezone.utc)
.isoformat(timespec="microseconds")
.replace("+00:00", "Z")
if value
else None
datetime: lambda value: (
value.astimezone(timezone.utc)
.isoformat(timespec="microseconds")
.replace("+00:00", "Z")
)
},
)
@@ -19,6 +21,7 @@ class BaseConfig(BaseModel):
class CreateUser(BaseConfig):
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)
@field_validator("display_name")
@classmethod
@@ -29,8 +32,10 @@ class CreateUser(BaseConfig):
return value
class User(CreateUser):
class User(BaseConfig):
id: str
username: str
display_name: str
created_at: datetime
@@ -54,8 +59,10 @@ class CreateChat(BaseConfig):
return value
class Chat(CreateChat):
class Chat(BaseConfig):
id: str
title: str
member_ids: List[str]
created_at: datetime
@@ -71,10 +78,11 @@ class CreateMessage(BaseConfig):
return value
class Message(CreateMessage):
class Message(BaseConfig):
id: str
chat_id: str
sender_id: str
text: str
created_at: datetime