update
This commit is contained in:
@@ -14,7 +14,7 @@ from config import (
|
||||
USER_TABLE,
|
||||
)
|
||||
from middlewares import AuditLogMiddleware, Tenant, TenantMiddleware
|
||||
from models import Course, Org
|
||||
from models import Course
|
||||
from rules.course import create_course, update_course
|
||||
|
||||
router = Router()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from .address import router as address
|
||||
from .custom_pricing import router as custom_pricing
|
||||
from .policies import router as policies
|
||||
|
||||
__all__ = ['policies', 'address']
|
||||
__all__ = ['policies', 'address', 'custom_pricing']
|
||||
|
||||
@@ -17,12 +17,7 @@ router = Router()
|
||||
org_layer = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@router.get(
|
||||
'/<id>/address',
|
||||
compress=True,
|
||||
tags=['Organization'],
|
||||
summary='Get organization address',
|
||||
)
|
||||
@router.get('/<id>/address', compress=True, tags=['Organization'])
|
||||
def get_address(id: str):
|
||||
return org_layer.collection.get_item(
|
||||
KeyPair(id, 'metadata#address'),
|
||||
|
||||
61
http-api/app/routes/orgs/custom_pricing.py
Normal file
61
http-api/app/routes/orgs/custom_pricing.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from decimal import Decimal
|
||||
from http import HTTPStatus
|
||||
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from aws_lambda_powertools.event_handler.exceptions import (
|
||||
BadRequestError,
|
||||
)
|
||||
from layercake.dateutils import now
|
||||
from layercake.dynamodb import (
|
||||
DynamoDBPersistenceLayer,
|
||||
KeyPair,
|
||||
PartitionKey,
|
||||
)
|
||||
from pydantic import BaseModel
|
||||
from pydantic.types import UUID4
|
||||
|
||||
from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client
|
||||
from config import COURSE_TABLE
|
||||
|
||||
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(
|
||||
PartitionKey(f'CUSTOM_PRICING#ORG#{id}'),
|
||||
limit=100,
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@router.post('/<id>/custompricing', compress=True)
|
||||
def post_custom_pricing(id: str, payload: 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}',
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(str(payload.course_id), '0'),
|
||||
cond_expr='attribute_exists(sk)',
|
||||
exc_cls=CourseNotFoundError,
|
||||
)
|
||||
|
||||
return JSONResponse(status_code=HTTPStatus.CREATED)
|
||||
|
||||
|
||||
class CourseNotFoundError(BadRequestError): ...
|
||||
@@ -15,17 +15,12 @@ from config import USER_TABLE
|
||||
from rules.org import update_policies
|
||||
|
||||
router = Router()
|
||||
org_layer = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
user_layer = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@router.get(
|
||||
'/<id>/policies',
|
||||
compress=True,
|
||||
tags=['Organization'],
|
||||
summary='Get organization policies',
|
||||
)
|
||||
@router.get('/<id>/policies', compress=True, tags=['Organization'])
|
||||
def get_policies(id: str):
|
||||
return org_layer.collection.get_items(
|
||||
return user_layer.collection.get_items(
|
||||
TransactKey(id)
|
||||
+ SortKey('metadata#billing_policy', remove_prefix='metadata#')
|
||||
+ SortKey('metadata#payment_policy', remove_prefix='metadata#'),
|
||||
@@ -56,7 +51,7 @@ def put_policies(id: str, payload: Policies):
|
||||
id,
|
||||
payment_policy=payment_policy.model_dump() if payment_policy else {},
|
||||
billing_policy=billing_policy.model_dump() if billing_policy else {},
|
||||
persistence_layer=org_layer,
|
||||
persistence_layer=user_layer,
|
||||
)
|
||||
|
||||
return JSONResponse(
|
||||
|
||||
Reference in New Issue
Block a user