Add Book schema
This commit is contained in:
parent
238dc8473f
commit
220cd6f34e
@ -1,17 +1,16 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
|
||||
class BookBase(BaseModel):
|
||||
title: str = Field(..., min_length=1, max_length=200, description="Book title")
|
||||
author: str = Field(..., min_length=1, max_length=100, description="Book author")
|
||||
isbn: str = Field(..., min_length=10, max_length=13, description="Book ISBN")
|
||||
publication_year: Optional[int] = Field(None, ge=1000, le=2100, description="Year of publication")
|
||||
description: Optional[str] = Field(None, max_length=1000, description="Book description")
|
||||
publisher: Optional[str] = Field(None, max_length=100, description="Book publisher")
|
||||
available: bool = Field(default=True, description="Book availability status")
|
||||
price: Optional[int] = Field(None, ge=0, description="Book price")
|
||||
genre: Optional[str] = Field(None, max_length=50, description="Book genre")
|
||||
language: Optional[str] = Field(None, max_length=50, description="Book language")
|
||||
description: Optional[str] = Field(None, max_length=1000, description="Book description")
|
||||
price: Optional[int] = Field(None, ge=0, description="Book price")
|
||||
available: bool = Field(default=True, description="Book availability status")
|
||||
|
||||
class BookCreate(BookBase):
|
||||
class Config:
|
||||
@ -21,17 +20,17 @@ class BookCreate(BookBase):
|
||||
"author": "F. Scott Fitzgerald",
|
||||
"isbn": "9780743273565",
|
||||
"publication_year": 1925,
|
||||
"description": "A story of the fabulously wealthy Jay Gatsby",
|
||||
"publisher": "Scribner",
|
||||
"available": True,
|
||||
"price": 1499,
|
||||
"genre": "Fiction",
|
||||
"language": "English"
|
||||
"description": "A story of the fabulously wealthy Jay Gatsby",
|
||||
"price": 1499,
|
||||
"available": True
|
||||
}
|
||||
}
|
||||
|
||||
class Book(BookBase):
|
||||
id: int = Field(..., description="Book ID")
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
@ -42,11 +41,11 @@ class Book(BookBase):
|
||||
"author": "F. Scott Fitzgerald",
|
||||
"isbn": "9780743273565",
|
||||
"publication_year": 1925,
|
||||
"description": "A story of the fabulously wealthy Jay Gatsby",
|
||||
"publisher": "Scribner",
|
||||
"available": True,
|
||||
"price": 1499,
|
||||
"genre": "Fiction",
|
||||
"language": "English"
|
||||
"description": "A story of the fabulously wealthy Jay Gatsby",
|
||||
"price": 1499,
|
||||
"available": True,
|
||||
"created_at": "2023-01-01T00:00:00",
|
||||
"updated_at": "2023-01-01T00:00:00"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user