-
-
Notifications
You must be signed in to change notification settings - Fork 59
Add a Delete order lambda #940
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
amazon-q-developer
wants to merge
4
commits into
main
Choose a base branch
from
Q-DEV-issue-938-1746507092
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 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5460162
feat: add delete order functionality
amazon-q-developer[bot] c55d542
feat: implement order deletion endpoint
amazon-q-developer[bot] 06bba23
refactor: improve delete order functionality and add tests
amazon-q-developer[bot] 2e28160
refactor: improve delete order flow and add CDK infrastructure
amazon-q-developer[bot] 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
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 |
---|---|---|
@@ -1,6 +1,13 @@ | ||
class InternalServerException(Exception): | ||
"""Raised when an unexpected error occurs in the server""" | ||
pass | ||
|
||
|
||
class OrderNotFoundException(Exception): | ||
"""Raised when trying to access an order that doesn't exist""" | ||
pass | ||
|
||
|
||
class DynamicConfigurationException(Exception): | ||
"""Raised when AppConfig fails to return configuration data""" | ||
pass |
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
from pydantic import BaseModel, Field, field_validator | ||
|
||
from service.models.order import OrderId | ||
|
||
|
||
class CreateOrderRequest(BaseModel): | ||
customer_name: Annotated[str, Field(min_length=1, max_length=20, description='Customer name')] | ||
|
@@ -18,4 +20,4 @@ def check_order_item_count(cls, v): | |
|
||
|
||
class DeleteOrderRequest(BaseModel): | ||
order_id: Annotated[str, Field(min_length=36, max_length=36, description='Order ID as UUID')] | ||
order_id: OrderId | ||
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. add unit test for pydantic schema |
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 |
---|---|---|
|
@@ -12,10 +12,13 @@ class CreateOrderOutput(Order): | |
pass | ||
|
||
|
||
class DeleteOrderOutput(BaseModel): | ||
order_id: Annotated[str, Field(description='ID of the deleted order')] | ||
status: Annotated[str, Field(description='Status of the delete operation')] = 'deleted' | ||
|
||
|
||
class InternalServerErrorOutput(BaseModel): | ||
error: Annotated[str, Field(description='Error description')] = 'internal server error' | ||
|
||
|
||
class DeleteOrderOutput(Order): | ||
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. add unit test for pydantic schema |
||
pass | ||
|
||
|
||
class OrderNotFoundOutput(BaseModel): | ||
error: Annotated[str, Field(description='Error description')] = 'order not found' |
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import json | ||
import uuid | ||
from typing import Dict | ||
|
||
import pytest | ||
import requests | ||
|
||
from service.models.order import Order | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def api_gw_url(): | ||
import os | ||
url = os.environ.get('ORDER_API_GW_URL') | ||
if not url: | ||
raise ValueError('Missing environment variable: ORDER_API_GW_URL') | ||
return url | ||
|
||
|
||
def test_delete_order_flow(api_gw_url): | ||
# First create an order to delete | ||
customer_name = 'E2E Test Customer' | ||
order_item_count = 3 | ||
|
||
# Create order | ||
create_url = f"{api_gw_url}/api/orders/" | ||
create_response = requests.post( | ||
create_url, | ||
json={ | ||
'customer_name': customer_name, | ||
'order_item_count': order_item_count | ||
} | ||
) | ||
|
||
assert create_response.status_code == 200 | ||
created_order = create_response.json() | ||
order_id = created_order['id'] | ||
|
||
# Delete the order | ||
delete_url = f"{api_gw_url}/api/orders/delete" | ||
delete_response = requests.post( | ||
delete_url, | ||
json={ | ||
'order_id': order_id | ||
} | ||
) | ||
|
||
# Check the response | ||
assert delete_response.status_code == 200 | ||
deleted_order = delete_response.json() | ||
assert deleted_order['id'] == order_id | ||
assert deleted_order['name'] == customer_name | ||
assert deleted_order['item_count'] == order_item_count | ||
|
||
# Try to delete the same order again, should get a 404 | ||
delete_again_response = requests.post( | ||
delete_url, | ||
json={ | ||
'order_id': order_id | ||
} | ||
) | ||
|
||
assert delete_again_response.status_code == 404 | ||
assert delete_again_response.json()['error'] == 'order not found' | ||
|
||
|
||
def test_delete_nonexistent_order(api_gw_url): | ||
delete_url = f"{api_gw_url}/api/orders/delete" | ||
nonexistent_order_id = str(uuid.uuid4()) | ||
|
||
response = requests.post( | ||
delete_url, | ||
json={ | ||
'order_id': nonexistent_order_id | ||
} | ||
) | ||
|
||
assert response.status_code == 404 | ||
assert response.json()['error'] == 'order not found' | ||
|
||
|
||
def test_delete_invalid_order_id(api_gw_url): | ||
delete_url = f"{api_gw_url}/api/orders/delete" | ||
|
||
# Test with an invalid UUID | ||
response = requests.post( | ||
delete_url, | ||
json={ | ||
'order_id': 'not-a-uuid' | ||
} | ||
) | ||
|
||
# Should get a validation error | ||
assert response.status_code == 422 |
Oops, something went wrong.
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.
add cdk code that generates all the required resources, make sure to add at the correct place