add sample
This commit is contained in:
@@ -2,29 +2,36 @@ import json
|
||||
from http import HTTPStatus
|
||||
from typing import Annotated
|
||||
|
||||
import boto3
|
||||
from aws_lambda_powertools.event_handler.api_gateway import (
|
||||
Response,
|
||||
Router,
|
||||
)
|
||||
from aws_lambda_powertools.event_handler.exceptions import (
|
||||
BadRequestError as PowertoolsBadRequestError,
|
||||
)
|
||||
from elasticsearch import Elasticsearch
|
||||
from layercake.dynamodb import (
|
||||
ComposeKey,
|
||||
DynamoDBCollection,
|
||||
DynamoDBPersistenceLayer,
|
||||
KeyPair,
|
||||
MissingError,
|
||||
PartitionKey,
|
||||
)
|
||||
from pydantic import UUID4, BaseModel, StringConstraints
|
||||
|
||||
import elastic
|
||||
from boto3clients import dynamodb_client
|
||||
from models import User
|
||||
from settings import ELASTIC_CONN, USER_TABLE
|
||||
|
||||
|
||||
class BadRequestError(MissingError, PowertoolsBadRequestError): ...
|
||||
|
||||
|
||||
router = Router()
|
||||
dynamodb_client = boto3.client('dynamodb')
|
||||
user_layer = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
collect = DynamoDBCollection(user_layer)
|
||||
collect = DynamoDBCollection(user_layer, exception_cls=BadRequestError)
|
||||
elastic_client = Elasticsearch(**ELASTIC_CONN)
|
||||
|
||||
|
||||
@@ -47,7 +54,7 @@ def get_users():
|
||||
)
|
||||
|
||||
|
||||
@router.post('/', compress=True, tags=['User'], description='Create user')
|
||||
@router.post('/', compress=True, tags=['User'], summary='Create user')
|
||||
def post_user(payload: User):
|
||||
return Response(status_code=HTTPStatus.CREATED)
|
||||
|
||||
@@ -57,11 +64,21 @@ class NewPasswordPayload(BaseModel):
|
||||
new_password: Annotated[str, StringConstraints(min_length=6)]
|
||||
|
||||
|
||||
@router.patch('/<id>', compress=True, tags=['User'])
|
||||
@router.patch('/<id>', compress=True, tags=['User'], summary='')
|
||||
def patch_reset(id: str, payload: NewPasswordPayload):
|
||||
return Response(status_code=HTTPStatus.OK)
|
||||
|
||||
|
||||
@router.get('/<id>', compress=True, tags=['User'], summary='Get user')
|
||||
def get_user(id: str):
|
||||
return collect.get_item(KeyPair(id, '0'))
|
||||
|
||||
|
||||
@router.get('/<id>/idp', compress=True, include_in_schema=False)
|
||||
def get_idp(id: str):
|
||||
return []
|
||||
|
||||
|
||||
@router.get(
|
||||
'/<id>/emails',
|
||||
compress=True,
|
||||
|
||||
Reference in New Issue
Block a user