28 lines
767 B
Python

from pydantic import BaseModel, HttpUrl
from typing import Optional
from datetime import datetime
from uuid import UUID
# Base schema for ShortenedUrl, used for inheritance
class ShortenedUrlBase(BaseModel):
original_url: HttpUrl
user_id: UUID
# Schema for creating a new ShortenedUrl
class ShortenedUrlCreate(ShortenedUrlBase):
pass
# Schema for updating an existing ShortenedUrl (all fields optional)
class ShortenedUrlUpdate(ShortenedUrlBase):
original_url: Optional[HttpUrl] = None
user_id: Optional[UUID] = None
# Schema for representing a ShortenedUrl in responses
class ShortenedUrlSchema(ShortenedUrlBase):
id: UUID
shortened_url: str
created_at: datetime
updated_at: datetime
class Config:
orm_mode = True