45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from aws_lambda_powertools.event_handler.api_gateway import Router
|
|
from layercake.dynamodb import (
|
|
DynamoDBPersistenceLayer,
|
|
KeyPair,
|
|
SortKey,
|
|
TransactKey,
|
|
)
|
|
|
|
from boto3clients import dynamodb_client
|
|
from config import ORDER_TABLE
|
|
from exceptions import OrderNotFoundError
|
|
|
|
from .checkout import router as checkout
|
|
|
|
__all__ = ['checkout']
|
|
|
|
router = Router()
|
|
dyn = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
|
|
|
|
|
|
@router.get('/<order_id>')
|
|
def get_order(order_id: str):
|
|
order = dyn.collection.get_items(
|
|
TransactKey(order_id)
|
|
+ SortKey('0')
|
|
+ SortKey('ITEMS', rename_key='items')
|
|
+ SortKey('ADDRESS', rename_key='address')
|
|
+ SortKey('CREDIT_CARD', rename_key='credit_card')
|
|
+ SortKey('INVOICE', rename_key='invoice')
|
|
+ SortKey('NFSE', rename_key='nfse')
|
|
+ SortKey('FEE', rename_key='fee')
|
|
+ SortKey('TRANSACTION#STATS', rename_key='stats'),
|
|
)
|
|
|
|
if not order:
|
|
raise OrderNotFoundError('Order not found')
|
|
|
|
attempts = dyn.collection.query(KeyPair(order_id, 'TRANSACTION#ATTEMPT#'))
|
|
enrollments = dyn.collection.query(KeyPair(order_id, 'ENROLLMENT#'))
|
|
|
|
return order | {
|
|
'attempts': attempts['items'],
|
|
'enrollments': enrollments['items'],
|
|
}
|