feat: update API models for lab2
This commit is contained in:
+16
-8
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user