-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #385 from Petsamuel/main
resolve movie rater #326
- Loading branch information
Showing
3 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
from fastapi import FastAPI, HTTPException | ||
from dotenv import load_dotenv | ||
import os | ||
import requests | ||
|
||
load_dotenv() | ||
|
||
|
||
app= FastAPI ( | ||
|
||
title="MOVIE RATER API", | ||
description="The MovieRater API is your gateway to a world of cinematic exploration and user-generated movie ratings. This versatile API empowers developers to create dynamic movie-related applications, allowing users to rate, review, and discover films from a vast collection.", | ||
docs_url="/" | ||
) | ||
apiKey=os.getenv("API_KEY") | ||
apiToken=os.getenv("API_TOKEN") | ||
|
||
|
||
|
||
@app.get("/movies") | ||
async def get_popular_movies(): | ||
url=f"https://api.themoviedb.org/3/discover/movie?api_key={apiKey}&sort_by=popularity.desc" | ||
|
||
response = requests.get(url) | ||
if response.status_code != 200: | ||
raise HTTPException(status_code=response.status_code, detail=response.content) | ||
|
||
movie_data = response.json() | ||
|
||
return movie_data | ||
|
||
@app.get("/movies/{movie_id}") | ||
async def get_movie(movie_id: int): | ||
"""Get information about a movie.""" | ||
|
||
url = f"https://api.themoviedb.org/3/movie/{movie_id}?api_key={apiKey}" | ||
response = requests.get(url) | ||
|
||
if response.status_code != 200: | ||
raise HTTPException(status_code=response.status_code, detail=response.content) | ||
|
||
movie_data = response.json() | ||
|
||
return movie_data | ||
|
||
@app.post("/movies/{movie_id}/rate") | ||
async def rate_movie(movie_id: int, rating: int): | ||
"""Rate a movie.""" | ||
|
||
# Validate the rating. | ||
if rating not in range(1, 11): | ||
raise HTTPException(status_code=400, detail="Rating must be between 1 and 10.") | ||
|
||
# Save the rating to your database. | ||
|
||
# Return a success response. | ||
return {"message": "Movie rated successfully."} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
annotated-types==0.5.0 | ||
anyio==3.7.1 | ||
asyncpg==0.28.0 | ||
certifi==2023.7.22 | ||
charset-normalizer==3.3.0 | ||
fastapi==0.103.2 | ||
greenlet==2.0.2 | ||
idna==3.4 | ||
pydantic==2.4.2 | ||
pydantic_core==2.10.1 | ||
python-dotenv==1.0.0 | ||
requests==2.31.0 | ||
sniffio==1.3.0 | ||
SQLAlchemy==2.0.21 | ||
starlette==0.27.0 | ||
typing_extensions==4.8.0 | ||
urllib3==2.0.5 |