47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
# fastapi_url_manager/schemas.py
|
|
import uuid
|
|
from typing import List, Optional
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
from fastapi_users import schemas
|
|
|
|
# FastAPI-Users Schemas
|
|
class UserRead(schemas.BaseUser[uuid.UUID]):
|
|
is_superuser: bool
|
|
is_verified: bool
|
|
|
|
class UserCreate(schemas.BaseUserCreate):
|
|
is_superuser: bool = False
|
|
is_verified: bool = False
|
|
|
|
class UserUpdate(schemas.BaseUserUpdate):
|
|
is_superuser: Optional[bool] = None
|
|
is_verified: Optional[bool] = None
|
|
|
|
# URLList Schemas
|
|
class URLListBase(BaseModel):
|
|
name: str = Field(..., min_length=1, max_length=100)
|
|
urls: str = Field(..., min_length=1) # Textarea content
|
|
unique_slug: str = Field(..., min_length=3, max_length=50, pattern=r"^[a-zA-Z0-9_-]+$") # Slug format
|
|
is_public: bool = Field(default=False)
|
|
|
|
class URLListCreate(URLListBase):
|
|
pass
|
|
|
|
class URLListUpdate(URLListBase):
|
|
# Allow partial updates for name, urls, unique_slug, or is_public
|
|
name: Optional[str] = Field(None, min_length=1, max_length=100)
|
|
urls: Optional[str] = Field(None, min_length=1)
|
|
unique_slug: Optional[str] = Field(None, min_length=3, max_length=50, pattern=r"^[a-zA-Z0-9_-]+$")
|
|
is_public: Optional[bool] = Field(None)
|
|
|
|
class URLListRead(URLListBase):
|
|
id: uuid.UUID
|
|
owner_id: uuid.UUID
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
model_config = {"from_attributes": True} # Pydantic V2 syntax
|