add freeze subscription
This commit is contained in:
@@ -34,6 +34,11 @@ class SubscriptionRequiredError(ServiceError):
|
||||
super().__init__(HTTPStatus.NOT_ACCEPTABLE, msg)
|
||||
|
||||
|
||||
class SubscriptionFrozenError(ServiceError):
|
||||
def __init__(self, msg: str | dict):
|
||||
super().__init__(HTTPStatus.NOT_ACCEPTABLE, msg)
|
||||
|
||||
|
||||
class DeduplicationConflictError(ConflictError): ...
|
||||
|
||||
|
||||
@@ -90,15 +95,9 @@ def enroll(
|
||||
rename_key='subscription',
|
||||
table_name=USER_TABLE,
|
||||
)
|
||||
+ KeyPair(
|
||||
pk='SUBSCRIPTION',
|
||||
sk=f'ORG#{org_id}',
|
||||
rename_key='subscribed',
|
||||
table_name=USER_TABLE,
|
||||
)
|
||||
)
|
||||
|
||||
if 'subscribed' not in org:
|
||||
if 'subscription' not in org:
|
||||
raise SubscriptionRequiredError('Organization not subscribed')
|
||||
|
||||
ctx = {
|
||||
@@ -184,6 +183,15 @@ def enroll_now(enrollment: Enrollment, context: Context):
|
||||
exc_cls=SubscriptionRequiredError,
|
||||
table_name=USER_TABLE,
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(
|
||||
pk='SUBSCRIPTION#FREEZE',
|
||||
sk=f'ORG#{org.id}',
|
||||
),
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
exc_cls=SubscriptionFrozenError,
|
||||
table_name=USER_TABLE,
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': enrollment.id,
|
||||
@@ -292,6 +300,15 @@ def enroll_later(enrollment: Enrollment, context: Context):
|
||||
exc_cls=SubscriptionRequiredError,
|
||||
table_name=USER_TABLE,
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(
|
||||
pk='SUBSCRIPTION#FREEZE',
|
||||
sk=f'ORG#{org.id}',
|
||||
),
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
exc_cls=SubscriptionFrozenError,
|
||||
table_name=USER_TABLE,
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': pk,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from aws_lambda_powertools import Logger
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, SortKey, TransactKey
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey, TransactKey
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import USER_TABLE
|
||||
@@ -44,4 +44,9 @@ def get_org(org_id: str):
|
||||
+ SortKey('0')
|
||||
+ SortKey('METADATA#ADDRESS', rename_key='address')
|
||||
+ SortKey('METADATA#SUBSCRIPTION', rename_key='subscription')
|
||||
+ KeyPair(
|
||||
pk='SUBSCRIPTION#FREEZE',
|
||||
sk=SortKey(f'ORG#{org_id}'),
|
||||
rename_key='subscription_freeze',
|
||||
)
|
||||
)
|
||||
|
||||
@@ -42,15 +42,6 @@ def add(
|
||||
cond_expr='attribute_exists(sk)',
|
||||
exc_cls=OrgNotFoundError,
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': 'SUBSCRIPTION',
|
||||
'sk': f'ORG#{org_id}',
|
||||
'name': name,
|
||||
'created_at': now_,
|
||||
},
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': org_id,
|
||||
@@ -60,5 +51,14 @@ def add(
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': 'SUBSCRIPTION',
|
||||
'sk': f'ORG#{org_id}',
|
||||
'name': name,
|
||||
'created_at': now_,
|
||||
},
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
)
|
||||
|
||||
return JSONResponse(status_code=HTTPStatus.CREATED)
|
||||
|
||||
Reference in New Issue
Block a user