add fix
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import json
|
||||
from typing import TypedDict
|
||||
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from elasticsearch import Elasticsearch
|
||||
from layercake.dynamodb import (
|
||||
DynamoDBCollection,
|
||||
DynamoDBPersistenceLayer,
|
||||
KeyPair,
|
||||
SortKey,
|
||||
TransactKey,
|
||||
)
|
||||
@@ -13,6 +13,7 @@ from pydantic import UUID4, BaseModel
|
||||
|
||||
import elastic
|
||||
from boto3clients import dynamodb_client
|
||||
from enrollment import set_status_as_canceled
|
||||
from middlewares.audit_log_middleware import AuditLogMiddleware
|
||||
from middlewares.authorizer_middleware import User
|
||||
from settings import ELASTIC_CONN, ENROLLMENT_TABLE, USER_TABLE
|
||||
@@ -20,8 +21,8 @@ from settings import ELASTIC_CONN, ENROLLMENT_TABLE, USER_TABLE
|
||||
router = Router()
|
||||
elastic_client = Elasticsearch(**ELASTIC_CONN)
|
||||
enrollment_layer = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
user_layer = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
enrollment_collect = DynamoDBCollection(enrollment_layer)
|
||||
user_layer = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
user_collect = DynamoDBCollection(user_layer)
|
||||
|
||||
|
||||
@@ -50,7 +51,7 @@ def get_enrollment(id: str):
|
||||
+ SortKey('canceled_date')
|
||||
+ SortKey('archived_date')
|
||||
+ SortKey('cancel_policy')
|
||||
+ SortKey('parent_vacancy')
|
||||
+ SortKey('parent_vacancy', path_spec='vacancy')
|
||||
+ SortKey('lock', path_spec='hash')
|
||||
+ SortKey('author')
|
||||
+ SortKey('tenant')
|
||||
@@ -58,14 +59,11 @@ def get_enrollment(id: str):
|
||||
)
|
||||
|
||||
|
||||
class Course(TypedDict):
|
||||
id: str
|
||||
name: str
|
||||
|
||||
|
||||
class Cancel(BaseModel):
|
||||
id: UUID4 | str
|
||||
course: Course
|
||||
lock_hash: str
|
||||
course: dict = {}
|
||||
vacancy: dict = {}
|
||||
|
||||
|
||||
@router.patch(
|
||||
@@ -78,6 +76,16 @@ class Cancel(BaseModel):
|
||||
)
|
||||
def cancel(id: str, payload: Cancel):
|
||||
user: User = router.context['user']
|
||||
|
||||
set_status_as_canceled(
|
||||
id,
|
||||
lock_hash=payload.lock_hash,
|
||||
author=user.model_dump(), # type: ignore
|
||||
course=payload.course, # type: ignore
|
||||
vacancy_key=KeyPair.parse_obj(payload.vacancy),
|
||||
persistence_layer=enrollment_layer,
|
||||
)
|
||||
|
||||
return payload
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user