-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop #24
Open
TsvetanKichuk
wants to merge
9
commits into
mate-academy:main
Choose a base branch
from
TsvetanKichuk:develop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Develop #24
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ca4a39e
Add database session context manager and configure engine
TsvetanKichuk 2ae84ac
17.01 commit
TsvetanKichuk ae9d036
Update database URL to point to movies.db
TsvetanKichuk ecf95ac
Add DATABASE_URL parameter to get_db_contextmanager call
TsvetanKichuk ce9316f
Add requirements.txt for project dependencies
TsvetanKichuk 855109e
Refactor movies route to simplify and remove unused logic
TsvetanKichuk 37e8be5
Update movie schema fields and typing for better accuracy
TsvetanKichuk 398315d
Create a new file
TsvetanKichuk bf06045
Add paginated movie list and detailed movie retrieval endpoints
TsvetanKichuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
annotated-types==0.7.0 | ||
anyio==4.7.0 | ||
build==1.2.2.post1 | ||
CacheControl==0.14.2 | ||
certifi==2024.12.14 | ||
charset-normalizer==3.4.1 | ||
cleo==2.1.0 | ||
click==8.1.8 | ||
colorama==0.4.6 | ||
crashtest==0.4.1 | ||
distlib==0.3.9 | ||
dulwich==0.22.7 | ||
fastapi==0.115.6 | ||
fastjsonschema==2.21.1 | ||
filelock==3.16.1 | ||
flake8==7.1.1 | ||
greenlet==3.1.1 | ||
h11==0.14.0 | ||
httpcore==1.0.7 | ||
httpx==0.28.1 | ||
idna==3.10 | ||
iniconfig==2.0.0 | ||
installer==0.7.0 | ||
jaraco.classes==3.4.0 | ||
jaraco.context==6.0.1 | ||
jaraco.functools==4.1.0 | ||
keyring==25.6.0 | ||
mccabe==0.7.0 | ||
more-itertools==10.5.0 | ||
msgpack==1.1.0 | ||
numpy==2.2.1 | ||
packaging==24.2 | ||
pandas==2.2.3 | ||
pkginfo==1.12.0 | ||
platformdirs==4.3.6 | ||
pluggy==1.5.0 | ||
poetry==2.0.1 | ||
poetry-core==2.0.1 | ||
pycodestyle==2.12.1 | ||
pydantic==2.10.4 | ||
pydantic-settings==2.7.0 | ||
pydantic_core==2.27.2 | ||
pyflakes==3.2.0 | ||
pyproject_hooks==1.2.0 | ||
pytest==8.3.4 | ||
pytest-env==1.1.5 | ||
python-dateutil==2.9.0.post0 | ||
python-dotenv==1.0.1 | ||
pytz==2024.2 | ||
pywin32-ctypes==0.2.3 | ||
RapidFuzz==3.11.0 | ||
requests==2.32.3 | ||
requests-toolbelt==1.0.0 | ||
shellingham==1.5.4 | ||
six==1.17.0 | ||
sniffio==1.3.1 | ||
SQLAlchemy==2.0.36 | ||
-e git+https://github.com/TsvetanKichuk/py-fastapi-homework-1-task.git@2ae84ac4ba422cd86910b73070391e7184667237#egg=src | ||
starlette==0.41.3 | ||
tomlkit==0.13.2 | ||
tqdm==4.67.1 | ||
trove-classifiers==2025.1.10.15 | ||
typing_extensions==4.12.2 | ||
tzdata==2024.2 | ||
urllib3==2.3.0 | ||
uvicorn==0.34.0 | ||
virtualenv==20.28.1 |
Empty file.
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 |
---|---|---|
@@ -1 +1 @@ | ||
from config.settings import get_settings | ||
from src.config.settings import get_settings |
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
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
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 |
---|---|---|
|
@@ -3,8 +3,41 @@ | |
|
||
from database import get_db, MovieModel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The import statement for |
||
|
||
from src.schemas.movies import MovieListResponseSchema, MovieDetailResponseSchema | ||
|
||
router = APIRouter() | ||
|
||
|
||
# Write your code here | ||
|
||
@router.get("/movies/", response_model=MovieListResponseSchema) | ||
def get_movies( | ||
page: int = Query(default=1, ge=1, description="The page number(>= 1)"), | ||
per_page: int = Query(default=10, ge=1, le=20, description="Film quantity at the page (>= 1 и <= 20)"), | ||
db: Session = Depends(get_db) | ||
): | ||
total_items = db.query(MovieModel).count() | ||
if total_items == 0: | ||
raise HTTPException(status_code=404, detail="No movies found.") | ||
offset = (page - 1) * per_page | ||
movies = db.query(MovieModel).offset(offset).limit(per_page).all() | ||
base_url = "/movies/" | ||
prev_page = f"{base_url}?page={page - 1}&per_page={per_page}" if page > 1 else None | ||
next_page = f"{base_url}?page={page + 1}&per_page={per_page}" if offset + per_page < total_items else None | ||
if page is None or per_page is None: | ||
raise HTTPException(status_code=422, detail="Ensure this value is greater than or equal to 1") | ||
return { | ||
"movies": movies, | ||
"prev_page": prev_page, | ||
"next_page": next_page, | ||
"total_pages": (total_items + per_page - 1) // per_page, | ||
"total_items": total_items, | ||
} | ||
|
||
|
||
@router.get("/movies/{movie_id}/", response_model=MovieDetailResponseSchema) | ||
def get_movie_by_id(movie_id: int, db: Session = Depends(get_db)): | ||
movie = db.query(MovieModel).filter(MovieModel.id == movie_id).first() | ||
if not movie: | ||
raise HTTPException(status_code=404, detail="Movie with the given ID was not found.") | ||
|
||
return movie |
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 |
---|---|---|
@@ -1 +1,31 @@ | ||
# Write your code here | ||
import datetime | ||
|
||
from pydantic import BaseModel | ||
from typing import List, Optional | ||
|
||
|
||
class MovieDetailResponseSchema(BaseModel): | ||
id: int | ||
name: str | ||
date: datetime.date | ||
score: Optional[float] | ||
genre: Optional[str] | ||
overview: Optional[str] | ||
crew: Optional[str] | ||
orig_title: Optional[str] | ||
status: Optional[str] | ||
orig_lang: Optional[str] | ||
budget: Optional[int] | ||
revenue: Optional[float] | ||
country: Optional[str] | ||
|
||
class Config: | ||
from_attributes: True | ||
|
||
|
||
class MovieListResponseSchema(BaseModel): | ||
movies: List[MovieDetailResponseSchema] | ||
prev_page: Optional[str] | ||
next_page: Optional[str] | ||
total_pages: int | ||
total_items: int |
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
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
get_db_contextmanager
function is being called withDATABASE_URL
, but according to its definition, it does not accept any parameters. You should removeDATABASE_URL
from the call to fix this issue.