feat-(move2lab2, postgres settings, repo base and other)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import uuid
|
||||
from pydantic import BaseModel, Field, field_validator, ConfigDict
|
||||
|
||||
|
||||
class CreateChat(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
title: str = Field(..., min_length=1, max_length=100)
|
||||
member_ids: list[str] = Field(..., min_items=1, max_items=100)
|
||||
|
||||
|
||||
@field_validator("title")
|
||||
@classmethod
|
||||
def title_validate(cls, v: str) -> str:
|
||||
if not v.strip():
|
||||
raise ValueError("title shouldn't have only whitespaces and cannot be blank")
|
||||
return v
|
||||
|
||||
|
||||
@field_validator("member_ids")
|
||||
@classmethod
|
||||
def validate_member_ids(cls, v: list[str]) -> list[str]:
|
||||
if len(v) != len(set(v)):
|
||||
raise ValueError("Dublicates are prohibitated")
|
||||
|
||||
for ids in v:
|
||||
try:
|
||||
uuid.UUID(ids)
|
||||
except:
|
||||
raise ValueError(f'invalid UUID format was detected for member_id: {ids}')
|
||||
return v
|
||||
|
||||
|
||||
|
||||
class Chat(BaseModel):
|
||||
id: str
|
||||
title: str
|
||||
member_ids: list[str]
|
||||
created_at: str
|
||||
@@ -0,0 +1,15 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class ErrorDetail(BaseModel):
|
||||
code: str
|
||||
message: str
|
||||
request_id: str
|
||||
|
||||
|
||||
class ErrorResponse(BaseModel):
|
||||
detail: ErrorDetail
|
||||
|
||||
|
||||
class Health(BaseModel):
|
||||
status: str
|
||||
@@ -0,0 +1,22 @@
|
||||
from pydantic import BaseModel, Field, field_validator, ConfigDict
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
class CreateMessage(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
text: str = Field(..., min_length=1, max_length=4000)
|
||||
|
||||
@field_validator("text")
|
||||
@classmethod
|
||||
def validate_text(cls, v: str) -> str:
|
||||
if not v.strip():
|
||||
raise ValueError("Blank or text consisted only from whitespaces is prohibitated")
|
||||
return v
|
||||
|
||||
|
||||
class Message(BaseModel):
|
||||
id: str
|
||||
chat_id: str
|
||||
sender_id: str
|
||||
text: str
|
||||
created_at: str
|
||||
@@ -0,0 +1,7 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Any, Optional
|
||||
|
||||
|
||||
class PageResponse(BaseModel):
|
||||
items: list[Any]
|
||||
next_cursor: Optional[str] = None
|
||||
@@ -0,0 +1,22 @@
|
||||
from pydantic import BaseModel, Field, field_validator, ConfigDict
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@field_validator("display_name")
|
||||
@classmethod
|
||||
def validate_display_name(cls, v: str) -> str:
|
||||
if not v.strip():
|
||||
raise ValueError("Name cannot be whitespaces or none")
|
||||
return v
|
||||
|
||||
|
||||
class User(BaseModel):
|
||||
id: str
|
||||
username: str
|
||||
display_name: str
|
||||
created_at: str
|
||||
Reference in New Issue
Block a user