add email events
This commit is contained in:
@@ -6,10 +6,11 @@ from aws_lambda_powertools.event_handler.openapi.params import Path, Query
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import ORDER_TABLE
|
||||
from config import ORDER_TABLE, USER_TABLE
|
||||
|
||||
router = Router()
|
||||
order_layer = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
|
||||
user_layer = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@router.get('/<id>', compress=True, tags=['Billing'])
|
||||
@@ -22,6 +23,21 @@ def get_billing(
|
||||
KeyPair(
|
||||
pk=f'BILLING#ORG#{id}',
|
||||
sk=f'START#{start_date}#END#{end_date}',
|
||||
)
|
||||
),
|
||||
limit=100,
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
@router.get('/<id>/terms', compress=True, tags=['Billing'])
|
||||
def get_terms(id: Annotated[str, Path()]):
|
||||
return user_layer.collection.get_item(
|
||||
KeyPair(
|
||||
pk=id,
|
||||
sk='metadata#billing_policy',
|
||||
# Post-migration: uncomment the following line
|
||||
# sk='METADATA#BILLING_TERMS',
|
||||
),
|
||||
raise_on_error=False,
|
||||
default={},
|
||||
)
|
||||
|
||||
@@ -38,22 +38,22 @@ class CustomPricing(BaseModel):
|
||||
|
||||
|
||||
@router.post('/<id>/custompricing', compress=True)
|
||||
def post_custom_pricing(id: str, payload: CustomPricing):
|
||||
def post_custom_pricing(id: str, custom_princing: CustomPricing):
|
||||
now_ = now()
|
||||
|
||||
with course_layer.transact_writer() as transact:
|
||||
transact.put(
|
||||
item={
|
||||
'id': f'CUSTOM_PRICING#ORG#{id}',
|
||||
'sk': f'COURSE#{payload.course_id}',
|
||||
'unit_price': payload.unit_price,
|
||||
'sk': f'COURSE#{custom_princing.course_id}',
|
||||
'unit_price': custom_princing.unit_price,
|
||||
'created_at': now_,
|
||||
},
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
exc_cls=CoursConflictError,
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(str(payload.course_id), '0'),
|
||||
key=KeyPair(str(custom_princing.course_id), '0'),
|
||||
cond_expr='attribute_exists(sk)',
|
||||
exc_cls=CourseNotFoundError,
|
||||
)
|
||||
@@ -61,18 +61,18 @@ def post_custom_pricing(id: str, payload: CustomPricing):
|
||||
return JSONResponse(status_code=HTTPStatus.CREATED)
|
||||
|
||||
|
||||
class Delete(BaseModel):
|
||||
class DeleteCustomPricing(BaseModel):
|
||||
course_id: UUID4
|
||||
|
||||
|
||||
@router.delete('/<id>/custompricing', compress=True)
|
||||
def delete_custom_pricing(id: str, payload: Delete):
|
||||
if course_layer.delete_item(
|
||||
KeyPair(
|
||||
f'CUSTOM_PRICING#ORG#{id}',
|
||||
f'COURSE#{payload.course_id}',
|
||||
)
|
||||
):
|
||||
def delete_custom_pricing(id: str, custom_princing: DeleteCustomPricing):
|
||||
pair = KeyPair(
|
||||
f'CUSTOM_PRICING#ORG#{id}',
|
||||
f'COURSE#{custom_princing.course_id}',
|
||||
)
|
||||
|
||||
if course_layer.delete_item(pair):
|
||||
return JSONResponse(status_code=HTTPStatus.OK)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user