add fix
This commit is contained in:
@@ -2,6 +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,
|
||||
@@ -19,7 +20,7 @@ from layercake.dynamodb import (
|
||||
PartitionKey,
|
||||
PrefixKey,
|
||||
)
|
||||
from pydantic import UUID4, BaseModel, StringConstraints
|
||||
from pydantic import UUID4, BaseModel, EmailStr, StringConstraints
|
||||
|
||||
import cognito
|
||||
import elastic
|
||||
@@ -27,6 +28,7 @@ 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
|
||||
|
||||
|
||||
class BadRequestError(MissingError, PowertoolsBadRequestError): ...
|
||||
@@ -63,13 +65,13 @@ def post_user(payload: User):
|
||||
return Response(status_code=HTTPStatus.CREATED)
|
||||
|
||||
|
||||
class NewPassword(BaseModel):
|
||||
class Password(BaseModel):
|
||||
cognito_sub: UUID4
|
||||
new_password: Annotated[str, StringConstraints(min_length=6)]
|
||||
|
||||
|
||||
@router.patch('/<id>', compress=True, tags=['User'])
|
||||
def patch_newpassword(id: str, payload: NewPassword):
|
||||
@router.post('/<id>/password', compress=True, tags=['User'], include_in_schema=False)
|
||||
def new_password(id: str, payload: Password):
|
||||
return Response(status_code=HTTPStatus.OK)
|
||||
|
||||
|
||||
@@ -100,6 +102,38 @@ def get_emails(id: str):
|
||||
)
|
||||
|
||||
|
||||
class Email(BaseModel):
|
||||
email: EmailStr
|
||||
|
||||
|
||||
@router.post(
|
||||
'/<id>/emails',
|
||||
compress=True,
|
||||
tags=['User'],
|
||||
summary='Add user email',
|
||||
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(
|
||||
body=payload,
|
||||
content_type=content_types.APPLICATION_JSON,
|
||||
status_code=HTTPStatus.CREATED,
|
||||
)
|
||||
|
||||
|
||||
@router.delete(
|
||||
'/<id>/emails',
|
||||
compress=True,
|
||||
tags=['User'],
|
||||
summary='Delete user email',
|
||||
middlewares=[AuditLogMiddleware('EMAIL_DEL', user_collect, ('email',))],
|
||||
)
|
||||
def delete_email(id: str, payload: Email):
|
||||
assert del_email(id, payload.email, persistence_layer=user_layer)
|
||||
return payload
|
||||
|
||||
|
||||
@router.get(
|
||||
'/<id>/logs',
|
||||
compress=True,
|
||||
@@ -109,8 +143,8 @@ def get_emails(id: str):
|
||||
def get_logs(id: str):
|
||||
return user_collect.query(
|
||||
# Post-migration: uncomment to enable PartitionKey with a composite key (id with `logs` prefix).
|
||||
# PartitionKey(ComposeKey(id, prefix='logs')),
|
||||
PartitionKey(ComposeKey(id, prefix='log', delimiter=':')),
|
||||
# PartitionKey(ComposeKey(id, 'logs')),
|
||||
PartitionKey(ComposeKey(id, 'log', delimiter=':')),
|
||||
start_key=router.current_event.get_query_string_value('start_key', None),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user