49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
"""
|
|
Schema definitions for Comics.
|
|
"""
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
from pydantic import BaseModel, AnyUrl
|
|
|
|
from src.db.models.comic import Comic
|
|
|
|
|
|
class ComicResponse(BaseModel):
|
|
"""
|
|
Pydantic model for returning Comic objects.
|
|
"""
|
|
id: str
|
|
created_date: datetime
|
|
last_modified_date: datetime
|
|
version: int
|
|
title: str
|
|
publisher_id: str
|
|
current_order: bool
|
|
completed: bool
|
|
weblink: Optional[str]
|
|
|
|
def comic_to_response(comic: Comic) -> ComicResponse:
|
|
response: ComicResponse = ComicResponse(
|
|
id=comic.id,
|
|
created_date=comic.created_date,
|
|
last_modified_date=comic.last_modified_date,
|
|
version=comic.version,
|
|
title=comic.title,
|
|
publisher_id=comic.publisher_id,
|
|
current_order=comic.current_order,
|
|
completed=comic.completed,
|
|
weblink=comic.weblink
|
|
)
|
|
return response
|
|
|
|
|
|
class ComicSchema(BaseModel):
|
|
"""
|
|
Pydantic model for uploading Comic object.
|
|
"""
|
|
id: str
|
|
title: str
|
|
weblink: Optional[AnyUrl]
|
|
completed: Optional[bool]
|
|
current_order: Optional[bool]
|