diff --git a/endpoints/api/v1/endpoint.post.py b/endpoints/api/v1/endpoint.post.py new file mode 100644 index 0000000..1fe86a6 --- /dev/null +++ b/endpoints/api/v1/endpoint.post.py @@ -0,0 +1,48 @@ +from fastapi import APIRouter, Depends, HTTPException +from core.database import fake_users_db +from typing import List, Optional + +router = APIRouter() + +# Simulated movie database +fake_movies_db = { + "1": {"id": "1", "title": "The Matrix", "year": 1999, "rating": 8.7}, + "2": {"id": "2", "title": "Inception", "year": 2010, "rating": 8.8}, + "3": {"id": "3", "title": "Interstellar", "year": 2014, "rating": 8.6} +} + +@router.post("/movies") +async def fetch_movies( + year: Optional[int] = None, + rating_min: Optional[float] = None, + limit: int = 10 +): + """Fetch movies with optional filters""" + movies = list(fake_movies_db.values()) + + if year: + movies = [m for m in movies if m["year"] == year] + + if rating_min: + movies = [m for m in movies if m["rating"] >= rating_min] + + movies = movies[:limit] + + if not movies: + raise HTTPException(status_code=404, detail="No movies found matching criteria") + + return { + "message": "Movies fetched successfully", + "data": { + "movies": movies, + "count": len(movies) + }, + "metadata": { + "filters_applied": { + "year": year, + "rating_min": rating_min, + "limit": limit + }, + "total_available": len(fake_movies_db) + } + } \ No newline at end of file