26 lines
817 B
Python
26 lines
817 B
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from uuid import UUID
|
|
|
|
# Base schema for Book
|
|
class BookBase(BaseModel):
|
|
title: str = Field(..., description="Book title")
|
|
author: str = Field(..., description="Book author")
|
|
description: Optional[str] = Field(None, description="Book description")
|
|
page_count: int = Field(..., gt=0, description="Number of pages in the book")
|
|
genre: str = Field(..., description="Book genre")
|
|
|
|
# Schema for creating a new Book
|
|
class BookCreate(BookBase):
|
|
publisher_id: UUID = Field(..., description="ID of the book's publisher")
|
|
|
|
# Schema for Book responses
|
|
class BookSchema(BookBase):
|
|
id: UUID
|
|
publisher_id: UUID
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
orm_mode = True |