Repository navigation
2. Рудаков Андрей Вячеславович. 614 #77
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
Open
rudikkkk
wants to merge
3
commits into
python-department:main
Choose a base branch
from
rudikkkk:2
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,8 +11,8 @@ | |||||
|
|
||||||
| from typing import Final | ||||||
|
|
||||||
| from .crud import read_product, update_product # noqa: F401 | ||||||
| from .storage import ( # noqa: F401 | ||||||
| from .crud import read_product, update_product | ||||||
| from .storage import ( | ||||||
| NAME_INDEX, | ||||||
| PRICE_INDEX, | ||||||
| QUANTITY_INDEX, | ||||||
|
|
@@ -22,9 +22,15 @@ | |||||
|
|
||||||
| type CartLine = tuple[int, int] | ||||||
|
|
||||||
| # TODO: задайте позиции полей внутри кортежа CartLine | ||||||
| LINE_PRODUCT_ID_INDEX: Final = 0 | ||||||
| LINE_QUANTITY_INDEX: Final = 0 | ||||||
| LINE_QUANTITY_INDEX: Final = 1 | ||||||
|
|
||||||
|
|
||||||
| def find_cart_line(cart: list[CartLine], product_id: int) -> CartLine | None: | ||||||
| for line in cart: | ||||||
| if line[LINE_PRODUCT_ID_INDEX] == product_id: | ||||||
| return line | ||||||
| return None | ||||||
|
|
||||||
|
|
||||||
| def add_to_cart( | ||||||
|
|
@@ -53,8 +59,30 @@ def add_to_cart( | |||||
| The cart line for ``product_id`` after the addition, or ``None`` | ||||||
| when the product is unknown or the store cannot cover the request. | ||||||
| """ | ||||||
| # TODO: реализуйте функцию | ||||||
| return (0, 0) | ||||||
| product = read_product(storage, product_id) | ||||||
| if not product: | ||||||
| return None | ||||||
| if product[QUANTITY_INDEX] < quantity: | ||||||
| print( | ||||||
| f"not enough stock for product {product_id}: {product[QUANTITY_INDEX]} available, {quantity} requested" | ||||||
| ) | ||||||
| return None | ||||||
| update_product( | ||||||
| storage, | ||||||
| product_id, | ||||||
| (product[NAME_INDEX], product[PRICE_INDEX], product[QUANTITY_INDEX] - quantity), | ||||||
| ) | ||||||
|
|
||||||
| line = find_cart_line(cart, product_id) | ||||||
| if line: | ||||||
| cart.remove(line) | ||||||
| updated_line = (product_id, line[LINE_QUANTITY_INDEX] + quantity) | ||||||
| cart.append(updated_line) | ||||||
| return updated_line | ||||||
| else: | ||||||
| new_line = (product_id, quantity) | ||||||
| cart.append(new_line) | ||||||
| return new_line | ||||||
|
|
||||||
|
|
||||||
| def remove_from_cart( | ||||||
|
|
@@ -85,5 +113,32 @@ def remove_from_cart( | |||||
| zero means the line was dropped), or ``None`` when the cart has no | ||||||
| line for the product or holds too few units. | ||||||
| """ | ||||||
| # TODO: реализуйте функцию | ||||||
| return (0, 0) | ||||||
| line = find_cart_line(cart, product_id) | ||||||
| if not line: | ||||||
| print(f"product {product_id} is not in the cart") | ||||||
| return None | ||||||
|
|
||||||
| if line[LINE_QUANTITY_INDEX] < quantity: | ||||||
| print( | ||||||
| f"cart holds only {line[LINE_QUANTITY_INDEX]} unit(s) of product {product_id}, cannot remove {quantity}" | ||||||
| ) | ||||||
| return None | ||||||
|
|
||||||
| product = read_product(storage, product_id) | ||||||
| if not product: | ||||||
|
Member
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. Все же с
Suggested change
|
||||||
| print("read_product") | ||||||
|
Member
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. Похоже, вы забыли удалить отладочный |
||||||
| return None | ||||||
|
|
||||||
| update_product( | ||||||
| storage, | ||||||
| product_id, | ||||||
| (product[NAME_INDEX], product[PRICE_INDEX], product[QUANTITY_INDEX] + quantity), | ||||||
| ) | ||||||
|
|
||||||
| cart.remove(line) | ||||||
| if line[LINE_QUANTITY_INDEX] - quantity == 0: | ||||||
| return (product_id, 0) | ||||||
|
|
||||||
| updated_line = (product_id, line[LINE_QUANTITY_INDEX] - quantity) | ||||||
| cart.append(updated_line) | ||||||
| return updated_line | ||||||
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Нарушение критерия
T1. Минус 0.25 балла