Add Game schema
This commit is contained in:
parent
a5a7959d18
commit
28b122f7e7
38
schemas/game.py
Normal file
38
schemas/game.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
from pydantic import BaseModel, Field
|
||||||
|
from typing import Optional
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
class GameBase(BaseModel):
|
||||||
|
title: str = Field(..., min_length=1, max_length=100, description="Game title")
|
||||||
|
description: Optional[str] = Field(None, description="Game description")
|
||||||
|
price: float = Field(..., gt=0, description="Game price")
|
||||||
|
genre: Optional[str] = Field(None, description="Game genre")
|
||||||
|
publisher: Optional[str] = Field(None, description="Game publisher")
|
||||||
|
release_date: Optional[datetime] = Field(None, description="Game release date")
|
||||||
|
rating: float = Field(default=0.0, ge=0, le=5, description="Game rating")
|
||||||
|
in_stock: bool = Field(default=True, description="Game availability status")
|
||||||
|
stock_quantity: int = Field(default=0, ge=0, description="Available quantity in stock")
|
||||||
|
|
||||||
|
class GameCreate(GameBase):
|
||||||
|
class Config:
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"title": "The Legend of Zelda",
|
||||||
|
"description": "Action-adventure game",
|
||||||
|
"price": 59.99,
|
||||||
|
"genre": "Adventure",
|
||||||
|
"publisher": "Nintendo",
|
||||||
|
"release_date": "2023-05-12T00:00:00",
|
||||||
|
"rating": 4.8,
|
||||||
|
"in_stock": True,
|
||||||
|
"stock_quantity": 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Game(GameBase):
|
||||||
|
id: int = Field(..., description="Game ID")
|
||||||
|
created_at: datetime
|
||||||
|
updated_at: datetime
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
Loading…
x
Reference in New Issue
Block a user