add delete
This commit is contained in:
@@ -22,11 +22,6 @@ router = Router()
|
||||
course_layer = DynamoDBPersistenceLayer(COURSE_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
class CustomPricing(BaseModel):
|
||||
course_id: UUID4
|
||||
unit_price: Decimal
|
||||
|
||||
|
||||
@router.get('/<id>/custompricing', compress=True)
|
||||
def get_custom_pricing(id: str):
|
||||
result = course_layer.collection.query(
|
||||
@@ -37,6 +32,11 @@ def get_custom_pricing(id: str):
|
||||
return result
|
||||
|
||||
|
||||
class CustomPricing(BaseModel):
|
||||
course_id: UUID4
|
||||
unit_price: Decimal
|
||||
|
||||
|
||||
@router.post('/<id>/custompricing', compress=True)
|
||||
def post_custom_pricing(id: str, payload: CustomPricing):
|
||||
now_ = now()
|
||||
@@ -46,8 +46,11 @@ def post_custom_pricing(id: str, payload: CustomPricing):
|
||||
item={
|
||||
'id': f'CUSTOM_PRICING#ORG#{id}',
|
||||
'sk': f'COURSE#{payload.course_id}',
|
||||
'unit_price': payload.unit_price,
|
||||
'created_at': now_,
|
||||
}
|
||||
},
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
exc_cls=CoursConflictError,
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(str(payload.course_id), '0'),
|
||||
@@ -58,4 +61,22 @@ def post_custom_pricing(id: str, payload: CustomPricing):
|
||||
return JSONResponse(status_code=HTTPStatus.CREATED)
|
||||
|
||||
|
||||
class Delete(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}',
|
||||
)
|
||||
):
|
||||
return JSONResponse(status_code=HTTPStatus.OK)
|
||||
|
||||
|
||||
class CoursConflictError(BadRequestError): ...
|
||||
|
||||
|
||||
class CourseNotFoundError(BadRequestError): ...
|
||||
|
||||
Reference in New Issue
Block a user