add typing
This commit is contained in:
@@ -2,11 +2,7 @@ import json
|
||||
from http import HTTPStatus
|
||||
from typing import Annotated
|
||||
|
||||
from aws_lambda_powertools.event_handler import content_types
|
||||
from aws_lambda_powertools.event_handler.api_gateway import (
|
||||
Response,
|
||||
Router,
|
||||
)
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from aws_lambda_powertools.event_handler.exceptions import (
|
||||
BadRequestError as PowertoolsBadRequestError,
|
||||
)
|
||||
@@ -24,12 +20,12 @@ from pydantic import UUID4, BaseModel, EmailStr, StringConstraints
|
||||
|
||||
import cognito
|
||||
import elastic
|
||||
import middlewares
|
||||
from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client, idp_client
|
||||
from middlewares import AuditLogMiddleware
|
||||
from models import User
|
||||
from settings import ELASTIC_CONN, USER_POOOL_ID, USER_TABLE
|
||||
from user import add_email, del_email
|
||||
from user import add_email, del_email, set_email_as_primary
|
||||
|
||||
|
||||
class BadRequestError(MissingError, PowertoolsBadRequestError): ...
|
||||
@@ -63,7 +59,7 @@ def get_users():
|
||||
middlewares=[AuditLogMiddleware('USER_ADD', user_collect)],
|
||||
)
|
||||
def post_user(payload: User):
|
||||
return Response(status_code=HTTPStatus.CREATED)
|
||||
return JSONResponse(status_code=HTTPStatus.CREATED)
|
||||
|
||||
|
||||
class Password(BaseModel):
|
||||
@@ -87,13 +83,11 @@ def password(id: str, payload: Password):
|
||||
user_pool_id=USER_POOOL_ID,
|
||||
idp_client=idp_client,
|
||||
)
|
||||
|
||||
return Response(
|
||||
return JSONResponse(
|
||||
body={
|
||||
'id': id,
|
||||
'cognito_sub': payload.cognito_sub,
|
||||
},
|
||||
content_type=content_types.APPLICATION_JSON,
|
||||
status_code=HTTPStatus.OK,
|
||||
)
|
||||
|
||||
@@ -137,14 +131,46 @@ class Email(BaseModel):
|
||||
middlewares=[AuditLogMiddleware('EMAIL_ADD', user_collect, ('email',))],
|
||||
)
|
||||
def post_email(id: str, payload: Email):
|
||||
assert add_email(id, payload.email, persistence_layer=user_layer)
|
||||
return Response(
|
||||
add_email(id, payload.email, persistence_layer=user_layer)
|
||||
return JSONResponse(
|
||||
body=payload,
|
||||
content_type=content_types.APPLICATION_JSON,
|
||||
status_code=HTTPStatus.CREATED,
|
||||
)
|
||||
|
||||
|
||||
class EmailAsPrimary(BaseModel):
|
||||
new_email: EmailStr
|
||||
old_email: EmailStr
|
||||
email_verified: bool = False
|
||||
|
||||
|
||||
@router.patch(
|
||||
'/<id>/emails',
|
||||
compress=True,
|
||||
tags=['User'],
|
||||
summary='Add user email as primary',
|
||||
middlewares=[
|
||||
AuditLogMiddleware(
|
||||
'EMAIL_CHANGE',
|
||||
user_collect,
|
||||
(
|
||||
'new_email',
|
||||
'old_email',
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
def patch_email(id: str, payload: EmailAsPrimary):
|
||||
set_email_as_primary(
|
||||
id,
|
||||
payload.new_email,
|
||||
payload.old_email,
|
||||
email_verified=payload.email_verified,
|
||||
persistence_layer=user_layer,
|
||||
)
|
||||
return JSONResponse(body=payload, status_code=HTTPStatus.OK)
|
||||
|
||||
|
||||
@router.delete(
|
||||
'/<id>/emails',
|
||||
compress=True,
|
||||
|
||||
Reference in New Issue
Block a user