forked from mtusi2026/mtusi2026lab5
Add 4 lab code
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import Field, StrictStr, field_validator
|
||||
|
||||
from .common import ContractModel
|
||||
|
||||
|
||||
|
||||
class CreateChat(ContractModel):
|
||||
title: StrictStr = Field(min_length=1, max_length=100)
|
||||
member_ids: List[StrictStr] = Field(min_length=1, max_length=100)
|
||||
|
||||
@field_validator("title")
|
||||
def validate_title(cls, value):
|
||||
if not value.strip():
|
||||
raise ValueError("blank title")
|
||||
return value
|
||||
|
||||
@field_validator("member_ids")
|
||||
def validate_member_ids(cls, value):
|
||||
if len(value) != len(set(value)):
|
||||
raise ValueError("duplicate member_ids")
|
||||
return value
|
||||
|
||||
|
||||
class Chat(ContractModel):
|
||||
id: str
|
||||
title: str
|
||||
member_ids: List[str]
|
||||
created_at: str
|
||||
|
||||
|
||||
class ChatPage(ContractModel):
|
||||
items: List[Chat]
|
||||
next_cursor: Optional[str]
|
||||
Reference in New Issue
Block a user