Spaces:
Sleeping
Sleeping
File size: 1,582 Bytes
01d5a5d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | """
Space related request and response models
"""
from typing import List
from pydantic import BaseModel, Field, validator
import re
from datetime import datetime
class CreateSpaceRequest(BaseModel):
"""Create Space request model"""
title: str = Field(..., description="Space theme")
objective: str = Field(..., description="Space objective")
host: str = Field(..., description="Host endpoint")
participants: List[str] = Field(default_factory=list, description="Other participant endpoints")
@validator('host', 'participants')
def validate_endpoint(cls, v):
pattern = r'^https?://[^\s/$.?#].[^\s]*$'
if isinstance(v, str):
if not re.match(pattern, v):
raise ValueError(f"Invalid endpoint format: {v}")
return v
elif isinstance(v, list):
for endpoint in v:
if not re.match(pattern, endpoint):
raise ValueError(f"Invalid endpoint format: {endpoint}")
return v
return v
class SpaceResponse(BaseModel):
"""Space response model"""
id: str = Field(..., description="Space ID")
title: str = Field(..., description="Space theme")
objective: str = Field(..., description="Space objective")
host: str = Field(..., description="Host endpoint")
participants: List[str] = Field(..., description="Other participant endpoints")
create_time: datetime = Field(..., description="Creation time")
status: int = Field(..., description="Space status: 1- discussion in progress, 2- discussion ended")
|