
This commit implements a simple movie database backend inspired by IMDb. It includes: - API endpoints for movies, actors, directors and genres - SQLAlchemy models with relationships - Alembic migrations - Pydantic schemas for request/response validation - Search and filtering functionality - Health check endpoint - Complete documentation
72 lines
1.4 KiB
Python
72 lines
1.4 KiB
Python
from datetime import date
|
|
from typing import List, Optional
|
|
from pydantic import BaseModel
|
|
|
|
|
|
# Shared properties
|
|
class ActorBase(BaseModel):
|
|
name: str
|
|
birth_date: Optional[date] = None
|
|
bio: Optional[str] = None
|
|
photo_path: Optional[str] = None
|
|
|
|
|
|
# Properties to receive on actor creation
|
|
class ActorCreate(ActorBase):
|
|
pass
|
|
|
|
|
|
# Properties to receive on actor update
|
|
class ActorUpdate(ActorBase):
|
|
name: Optional[str] = None
|
|
|
|
|
|
# Properties shared by models stored in DB
|
|
class ActorInDBBase(ActorBase):
|
|
id: int
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Properties to return to client
|
|
class Actor(ActorInDBBase):
|
|
pass
|
|
|
|
|
|
# Properties properties stored in DB
|
|
class ActorInDB(ActorInDBBase):
|
|
pass
|
|
|
|
|
|
# Properties for actor with movie role
|
|
class ActorWithRole(Actor):
|
|
character_name: Optional[str] = None
|
|
|
|
|
|
# Properties for actor with details
|
|
class ActorDetails(Actor):
|
|
movies: List["MovieWithRole"] = []
|
|
|
|
|
|
|
|
# We need a simplified movie class to avoid circular import issues
|
|
class MovieWithRole(BaseModel):
|
|
id: int
|
|
title: str
|
|
release_date: Optional[date] = None
|
|
poster_path: Optional[str] = None
|
|
character_name: Optional[str] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Update forward references
|
|
ActorDetails.model_rebuild()
|
|
|
|
|
|
# Properties for list
|
|
class ActorList(BaseModel):
|
|
data: List[Actor]
|
|
total: int |