remove METADATA#COURSE
This commit is contained in:
@@ -12,7 +12,13 @@ from layercake.dateutils import fromisoformat, now
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey
|
||||
|
||||
from boto3clients import dynamodb_client, s3_client
|
||||
from config import BUCKET_NAME, ENROLLMENT_TABLE, PAPERFORGE_API, SIGNATURE_URI
|
||||
from config import (
|
||||
BUCKET_NAME,
|
||||
COURSE_TABLE,
|
||||
ENROLLMENT_TABLE,
|
||||
PAPERFORGE_API,
|
||||
SIGNATURE_URI,
|
||||
)
|
||||
|
||||
logger = Logger(__name__)
|
||||
dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
@@ -24,10 +30,12 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
new_image = event.detail['new_image']
|
||||
now_ = now()
|
||||
enrollment_id = new_image['id']
|
||||
course_id = new_image['course']['id']
|
||||
cert = dyn.collection.get_item(
|
||||
KeyPair(
|
||||
pk=new_image['id'],
|
||||
sk=SortKey('METADATA#COURSE', path_spec='cert', rename_key='cert'),
|
||||
pk=course_id,
|
||||
sk=SortKey('0', path_spec='cert', rename_key='cert'),
|
||||
table_name=COURSE_TABLE,
|
||||
),
|
||||
raise_on_error=False,
|
||||
default=False,
|
||||
|
||||
@@ -24,7 +24,6 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
metadata = dyn.collection.get_items(
|
||||
TransactKey(new_image['id'])
|
||||
+ SortKey('METADATA#SUBSCRIPTION_COVERED', rename_key='subscription')
|
||||
+ SortKey('METADATA#COURSE', rename_key='course')
|
||||
+ SortKey(
|
||||
'METADATA#DEDUPLICATION_WINDOW',
|
||||
path_spec='offset_days',
|
||||
@@ -38,7 +37,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
flatten_top=False,
|
||||
)
|
||||
user = User.model_validate(new_image['user'])
|
||||
course = Course.model_validate(new_image['course'] | metadata['course'])
|
||||
course = Course.model_validate(new_image['course'])
|
||||
subscription = metadata['subscription'] if 'subscription' in metadata else None
|
||||
enrollment = Enrollment(
|
||||
id=uuid4(),
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
from os import access
|
||||
|
||||
from aws_lambda_powertools import Logger
|
||||
from aws_lambda_powertools.utilities.data_classes import (
|
||||
EventBridgeEvent,
|
||||
event_source,
|
||||
)
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from glom import glom
|
||||
from layercake.dateutils import now, ttl
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey
|
||||
|
||||
@@ -26,14 +23,15 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
now_ = now()
|
||||
enrollment_id = new_image['id']
|
||||
user = new_image['user']
|
||||
course_name = glom(new_image, 'course.name')
|
||||
course_name = new_image['course']['name']
|
||||
|
||||
# Post-migration: after removing the stopgap file `patch_course_metadata.py`,
|
||||
# use `access_expires_at` from `new_image`
|
||||
access_period = int(
|
||||
dyn.collection.get_item(
|
||||
KeyPair(
|
||||
pk=enrollment_id,
|
||||
sk=SortKey('METADATA#COURSE', path_spec='access_period'),
|
||||
pk=new_image['course']['id'],
|
||||
sk=SortKey('0', path_spec='access_period'),
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -51,15 +51,6 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': new_image['id'],
|
||||
'sk': 'METADATA#COURSE',
|
||||
'created_at': now_,
|
||||
'access_period': access_period,
|
||||
'cert': course.get('cert', None),
|
||||
}
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.exception(exc)
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user