Update code in endpoints/api/v1/endpoint.post.py
This commit is contained in:
parent
adf7f176a4
commit
400e361288
48
endpoints/api/v1/endpoint.post.py
Normal file
48
endpoints/api/v1/endpoint.post.py
Normal file
@ -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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user