feat: update API models for lab2
This commit is contained in:
+16
-8
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
@@ -6,12 +7,13 @@ from pydantic import BaseModel, ConfigDict, Field, field_validator
|
|||||||
|
|
||||||
class BaseConfig(BaseModel):
|
class BaseConfig(BaseModel):
|
||||||
model_config = ConfigDict(
|
model_config = ConfigDict(
|
||||||
|
from_attributes=True,
|
||||||
json_encoders={
|
json_encoders={
|
||||||
datetime: lambda value: value.astimezone(timezone.utc)
|
datetime: lambda value: (
|
||||||
.isoformat(timespec="microseconds")
|
value.astimezone(timezone.utc)
|
||||||
.replace("+00:00", "Z")
|
.isoformat(timespec="microseconds")
|
||||||
if value
|
.replace("+00:00", "Z")
|
||||||
else None
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,6 +21,7 @@ class BaseConfig(BaseModel):
|
|||||||
class CreateUser(BaseConfig):
|
class CreateUser(BaseConfig):
|
||||||
username: str = Field(..., pattern=r"^[a-z0-9_]{3,32}$")
|
username: str = Field(..., pattern=r"^[a-z0-9_]{3,32}$")
|
||||||
display_name: str = Field(..., min_length=1, max_length=100)
|
display_name: str = Field(..., min_length=1, max_length=100)
|
||||||
|
password: str = Field(..., min_length=12, max_length=128)
|
||||||
|
|
||||||
@field_validator("display_name")
|
@field_validator("display_name")
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -29,8 +32,10 @@ class CreateUser(BaseConfig):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class User(CreateUser):
|
class User(BaseConfig):
|
||||||
id: str
|
id: str
|
||||||
|
username: str
|
||||||
|
display_name: str
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@@ -54,8 +59,10 @@ class CreateChat(BaseConfig):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class Chat(CreateChat):
|
class Chat(BaseConfig):
|
||||||
id: str
|
id: str
|
||||||
|
title: str
|
||||||
|
member_ids: List[str]
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
@@ -71,10 +78,11 @@ class CreateMessage(BaseConfig):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class Message(CreateMessage):
|
class Message(BaseConfig):
|
||||||
id: str
|
id: str
|
||||||
chat_id: str
|
chat_id: str
|
||||||
sender_id: str
|
sender_id: str
|
||||||
|
text: str
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user