add docs
This commit is contained in:
@@ -1,15 +1,28 @@
|
||||
import json
|
||||
from typing import Literal
|
||||
from typing import TypedDict
|
||||
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from elasticsearch import Elasticsearch
|
||||
from pydantic import BaseModel
|
||||
from layercake.dynamodb import (
|
||||
DynamoDBCollection,
|
||||
DynamoDBPersistenceLayer,
|
||||
SortKey,
|
||||
TransactKey,
|
||||
)
|
||||
from pydantic import UUID4, BaseModel
|
||||
|
||||
import elastic
|
||||
from settings import ELASTIC_CONN, ENROLLMENT_TABLE
|
||||
from boto3clients import dynamodb_client
|
||||
from middlewares.audit_log_middleware import AuditLogMiddleware
|
||||
from middlewares.authorizer_middleware import User
|
||||
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_collect = DynamoDBCollection(user_layer)
|
||||
|
||||
|
||||
@router.get('/', compress=True, tags=['Enrollment'])
|
||||
@@ -28,16 +41,44 @@ def get_enrollments():
|
||||
|
||||
@router.get('/<id>', compress=True, tags=['Enrollment'])
|
||||
def get_enrollment(id: str):
|
||||
return {}
|
||||
return enrollment_collect.get_items(
|
||||
TransactKey(id)
|
||||
+ SortKey('0')
|
||||
+ SortKey('started_date')
|
||||
+ SortKey('finished_date')
|
||||
+ SortKey('failed_date')
|
||||
+ SortKey('canceled_date')
|
||||
+ SortKey('archived_date')
|
||||
+ SortKey('cancel_policy')
|
||||
+ SortKey('parent_vacancy')
|
||||
+ SortKey('lock', path_spec='hash')
|
||||
+ SortKey('author')
|
||||
+ SortKey('tenant')
|
||||
+ SortKey('cert')
|
||||
)
|
||||
|
||||
|
||||
class CancelPayload(BaseModel):
|
||||
status: Literal['CANCELED'] = 'CANCELED'
|
||||
class Course(TypedDict):
|
||||
id: str
|
||||
name: str
|
||||
|
||||
|
||||
@router.patch('/<id>', compress=True, tags=['Enrollment'])
|
||||
def cancel(id: str, payload: CancelPayload):
|
||||
return {}
|
||||
class Cancel(BaseModel):
|
||||
id: UUID4 | str
|
||||
course: Course
|
||||
|
||||
|
||||
@router.patch(
|
||||
'/<id>/cancel',
|
||||
compress=True,
|
||||
tags=['Enrollment'],
|
||||
middlewares=[
|
||||
AuditLogMiddleware('ENROLLMENT_CANCEL', user_collect, ('id', 'course'))
|
||||
],
|
||||
)
|
||||
def cancel(id: str, payload: Cancel):
|
||||
user: User = router.context['user']
|
||||
return payload
|
||||
|
||||
|
||||
@router.post('/', compress=True, tags=['Enrollment'])
|
||||
|
||||
Reference in New Issue
Block a user