add validation to data
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
from decimal import Decimal
|
||||
from http import HTTPStatus
|
||||
from typing import Any
|
||||
from typing import Annotated, Any
|
||||
|
||||
from aws_lambda_powertools import Logger, Tracer
|
||||
from aws_lambda_powertools.event_handler.api_gateway import (
|
||||
APIGatewayHttpResolver,
|
||||
Response,
|
||||
)
|
||||
from aws_lambda_powertools.event_handler.openapi.params import Body
|
||||
from aws_lambda_powertools.logging import correlation_paths
|
||||
from aws_lambda_powertools.utilities.typing import LambdaContext
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey
|
||||
@@ -23,28 +24,27 @@ dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
|
||||
@app.post('/')
|
||||
@tracer.capture_method
|
||||
def postback():
|
||||
json_body = app.current_event.json_body
|
||||
|
||||
event_name = json_body['event_name']
|
||||
score = round(Decimal(json_body['APROVEITAMENTO']), 2)
|
||||
progress = round(Decimal(json_body['ANDAMENTO']), 2)
|
||||
def postback(
|
||||
status: Annotated[str, Body(embed=True)],
|
||||
konviva_id: Annotated[str, Body(alias='ID_MATRICULA', embed=True)],
|
||||
score: Annotated[Decimal, Body(alias='APROVEITAMENTO', embed=True)],
|
||||
progress: Annotated[Decimal, Body(alias='ANDAMENTO', embed=True)],
|
||||
):
|
||||
score = score.quantize(Decimal('0.00'))
|
||||
progress = progress.quantize(Decimal('0.00'))
|
||||
enrollment_id = dyn.collection.get_item(
|
||||
KeyPair(
|
||||
# Post-migration: uncomment the following line
|
||||
# pk='KONVIVA',
|
||||
pk='konviva',
|
||||
sk=SortKey(
|
||||
json_body['ID_MATRICULA'],
|
||||
path_spec='enrollment_id',
|
||||
),
|
||||
sk=SortKey(konviva_id, path_spec='enrollment_id'),
|
||||
),
|
||||
exc_cls=EnrollmentNotFoundError,
|
||||
)
|
||||
|
||||
# Make sure webhooks send the correct event names
|
||||
match event_name:
|
||||
case 'UPDATING':
|
||||
match status:
|
||||
case 'IN_PROGRESS':
|
||||
update_progress(
|
||||
enrollment_id,
|
||||
progress,
|
||||
|
||||
@@ -199,7 +199,6 @@ def _set_status_as_completed(
|
||||
start_dt=now_,
|
||||
days=cert_exp_interval - dedup_window_offset_days,
|
||||
)
|
||||
|
||||
transact.put(
|
||||
item={
|
||||
'id': id,
|
||||
@@ -309,14 +308,6 @@ def _set_status_as_failed(
|
||||
},
|
||||
exc_cls=EnrollmentConflictError,
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': id,
|
||||
'sk': 'FAILED',
|
||||
'created_at': now_,
|
||||
},
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
)
|
||||
# Remove reminders and events that no longer apply
|
||||
transact.delete(
|
||||
key=KeyPair(
|
||||
|
||||
Reference in New Issue
Block a user