update event
This commit is contained in:
@@ -9,15 +9,12 @@ from aws_lambda_powertools.utilities.data_classes import (
|
||||
)
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from layercake.dateutils import now
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
from sqlite_utils import Database
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import (
|
||||
COURSE_TABLE,
|
||||
ENROLLMENT_TABLE,
|
||||
SQLITE_DATABASE,
|
||||
SQLITE_TABLE,
|
||||
)
|
||||
|
||||
sqlite3.register_converter('json', json.loads)
|
||||
@@ -72,23 +69,24 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
|
||||
|
||||
class CourseNotFoundError(Exception):
|
||||
def __init__(self, *args):
|
||||
super().__init__('Course not found in SQLite')
|
||||
super().__init__('Course not found')
|
||||
|
||||
|
||||
def _get_course(course_id: str) -> dict:
|
||||
course = course_layer.get_item(KeyPair(pk=course_id, sk='0'))
|
||||
def _get_course(id: str) -> dict:
|
||||
course = course_layer.get_item(KeyPair(pk=id, sk='0'))
|
||||
if course:
|
||||
return course
|
||||
|
||||
with sqlite3.connect(
|
||||
database=SQLITE_DATABASE, detect_types=sqlite3.PARSE_DECLTYPES
|
||||
) as conn:
|
||||
db = Database(conn)
|
||||
rows = db[SQLITE_TABLE].rows_where(
|
||||
"json->>'$.metadata__betaeducacao_id' = ?", [course_id]
|
||||
)
|
||||
|
||||
for row in rows:
|
||||
return row['json']
|
||||
|
||||
raise CourseNotFoundError
|
||||
course_id = course_layer.collection.get_item(
|
||||
KeyPair(
|
||||
pk='MIGRATION',
|
||||
sk=SortKey(
|
||||
f'COURSE#{id}',
|
||||
path_spec='course_id',
|
||||
),
|
||||
),
|
||||
exc_cls=CourseNotFoundError,
|
||||
)
|
||||
return course_layer.collection.get_item(
|
||||
KeyPair(pk=course_id, sk='0'),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user