aws-samples / retail-demo-store

AWS Retail Demo Store is a sample retail web application and workshop platform demonstrating how AWS infrastructure and services can be used to build compelling customer experiences for eCommerce, retail, and digital marketing use-cases
MIT No Attribution
726 stars 515 forks source link

Update `get_all` Method in db.py to Retrieve All Items from DynamoDB table #642

Closed MustaphaU closed 1 month ago

MustaphaU commented 1 month ago

This update modifies the get_all method to ensure that all items from the DynamoDB table are retrieved during a scan operation.

Issue #, if available:

639

Description of changes: Update get_all Method in db.py to Retrieve All Items from DynamoDB Table

Reason for Change:

Updated get_all method:

def get_all(self):
    items = []
    response = self.table.scan()
    while 'LastEvaluatedKey' in response:
        items.extend(response['Items'])
        response = self.table.scan(ExclusiveStartKey=response['LastEvaluatedKey'])
    items.extend(response['Items'])
    return items

Description of testing performed to validate your changes (required if pull request includes CloudFormation or source code changes):

Test:

all_products_resp = requests.get('http://{}/products/all'.format(products_service_instance))

all_products = all_products_resp.json()
print(len(all_products))

Output is 2465 representing all products.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

MustaphaU commented 1 month ago

Thanks for the contribution !

Thank you @BastLeblanc !