Updated folder structure (for Docker)
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
"""Movie use cases."""
|
||||
|
||||
from .dto import SearchMovieResponse
|
||||
from .search_movie import SearchMovieUseCase
|
||||
|
||||
__all__ = [
|
||||
"SearchMovieUseCase",
|
||||
"SearchMovieResponse",
|
||||
]
|
||||
@@ -0,0 +1,44 @@
|
||||
"""Movie application DTOs."""
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class SearchMovieResponse:
|
||||
"""Response from searching for a movie."""
|
||||
|
||||
status: str
|
||||
imdb_id: str | None = None
|
||||
title: str | None = None
|
||||
media_type: str | None = None
|
||||
tmdb_id: int | None = None
|
||||
overview: str | None = None
|
||||
release_date: str | None = None
|
||||
vote_average: float | None = None
|
||||
error: str | None = None
|
||||
message: str | None = None
|
||||
|
||||
def to_dict(self):
|
||||
"""Convert to dict for agent compatibility."""
|
||||
result = {"status": self.status}
|
||||
|
||||
if self.error:
|
||||
result["error"] = self.error
|
||||
result["message"] = self.message
|
||||
else:
|
||||
if self.imdb_id:
|
||||
result["imdb_id"] = self.imdb_id
|
||||
if self.title:
|
||||
result["title"] = self.title
|
||||
if self.media_type:
|
||||
result["media_type"] = self.media_type
|
||||
if self.tmdb_id:
|
||||
result["tmdb_id"] = self.tmdb_id
|
||||
if self.overview:
|
||||
result["overview"] = self.overview
|
||||
if self.release_date:
|
||||
result["release_date"] = self.release_date
|
||||
if self.vote_average:
|
||||
result["vote_average"] = self.vote_average
|
||||
|
||||
return result
|
||||
@@ -0,0 +1,93 @@
|
||||
"""Search movie use case."""
|
||||
|
||||
import logging
|
||||
|
||||
from infrastructure.api.tmdb import (
|
||||
TMDBAPIError,
|
||||
TMDBClient,
|
||||
TMDBConfigurationError,
|
||||
TMDBNotFoundError,
|
||||
)
|
||||
|
||||
from .dto import SearchMovieResponse
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SearchMovieUseCase:
|
||||
"""
|
||||
Use case for searching a movie and retrieving its IMDb ID.
|
||||
|
||||
This orchestrates the TMDB API client to find movie information.
|
||||
"""
|
||||
|
||||
def __init__(self, tmdb_client: TMDBClient):
|
||||
"""
|
||||
Initialize use case.
|
||||
|
||||
Args:
|
||||
tmdb_client: TMDB API client
|
||||
"""
|
||||
self.tmdb_client = tmdb_client
|
||||
|
||||
def execute(self, media_title: str) -> SearchMovieResponse:
|
||||
"""
|
||||
Search for a movie by title.
|
||||
|
||||
Args:
|
||||
media_title: Title of the movie to search for
|
||||
|
||||
Returns:
|
||||
SearchMovieResponse with movie information or error
|
||||
"""
|
||||
try:
|
||||
# Use the TMDB client to search for media
|
||||
result = self.tmdb_client.search_media(media_title)
|
||||
|
||||
# Check if IMDb ID was found
|
||||
if result.imdb_id:
|
||||
logger.info(f"IMDb ID found for '{media_title}': {result.imdb_id}")
|
||||
return SearchMovieResponse(
|
||||
status="ok",
|
||||
imdb_id=result.imdb_id,
|
||||
title=result.title,
|
||||
media_type=result.media_type,
|
||||
tmdb_id=result.tmdb_id,
|
||||
overview=result.overview,
|
||||
release_date=result.release_date,
|
||||
vote_average=result.vote_average,
|
||||
)
|
||||
else:
|
||||
logger.warning(f"No IMDb ID available for '{media_title}'")
|
||||
return SearchMovieResponse(
|
||||
status="ok",
|
||||
title=result.title,
|
||||
media_type=result.media_type,
|
||||
tmdb_id=result.tmdb_id,
|
||||
error="no_imdb_id",
|
||||
message=f"No IMDb ID available for '{result.title}'",
|
||||
)
|
||||
|
||||
except TMDBNotFoundError as e:
|
||||
logger.info(f"Media not found: {e}")
|
||||
return SearchMovieResponse(
|
||||
status="error", error="not_found", message=str(e)
|
||||
)
|
||||
|
||||
except TMDBConfigurationError as e:
|
||||
logger.error(f"TMDB configuration error: {e}")
|
||||
return SearchMovieResponse(
|
||||
status="error", error="configuration_error", message=str(e)
|
||||
)
|
||||
|
||||
except TMDBAPIError as e:
|
||||
logger.error(f"TMDB API error: {e}")
|
||||
return SearchMovieResponse(
|
||||
status="error", error="api_error", message=str(e)
|
||||
)
|
||||
|
||||
except ValueError as e:
|
||||
logger.error(f"Validation error: {e}")
|
||||
return SearchMovieResponse(
|
||||
status="error", error="validation_failed", message=str(e)
|
||||
)
|
||||
Reference in New Issue
Block a user