update profile
This commit is contained in:
@@ -10,9 +10,11 @@ from elasticsearch import Elasticsearch
|
||||
from layercake.dynamodb import (
|
||||
DynamoDBCollection,
|
||||
DynamoDBPersistenceLayer,
|
||||
KeyPair,
|
||||
MissingError,
|
||||
SortKey,
|
||||
TransactKey,
|
||||
)
|
||||
from layercake.extra_types import CpfStr, NameStr
|
||||
from pydantic import UUID4, BaseModel, StringConstraints
|
||||
|
||||
import cognito
|
||||
@@ -21,6 +23,7 @@ from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client, idp_client
|
||||
from middlewares import AuditLogMiddleware
|
||||
from models import User
|
||||
from rules.user import update_user
|
||||
from settings import ELASTIC_CONN, USER_POOOL_ID, USER_TABLE
|
||||
|
||||
from .emails import router as emails
|
||||
@@ -65,6 +68,46 @@ def post_user(payload: User):
|
||||
return JSONResponse(status_code=HTTPStatus.CREATED)
|
||||
|
||||
|
||||
class UserData(BaseModel):
|
||||
name: NameStr
|
||||
cpf: CpfStr
|
||||
|
||||
|
||||
@router.put(
|
||||
'/<id>',
|
||||
compress=True,
|
||||
tags=['User'],
|
||||
summary='Update user',
|
||||
middlewares=[
|
||||
AuditLogMiddleware('USER_UPDATE', user_collect, ('id', 'name', 'new_cpf'))
|
||||
],
|
||||
)
|
||||
def put_user(id: str, payload: UserData):
|
||||
update_user(
|
||||
{
|
||||
'id': id,
|
||||
'name': payload.name,
|
||||
'cpf': payload.cpf,
|
||||
},
|
||||
persistence_layer=user_layer,
|
||||
)
|
||||
return JSONResponse(
|
||||
body={
|
||||
'id': id,
|
||||
'name': payload.name,
|
||||
'new_cpf': payload.cpf,
|
||||
},
|
||||
status_code=HTTPStatus.OK,
|
||||
)
|
||||
|
||||
|
||||
@router.get('/<id>', compress=True, tags=['User'], summary='Get user')
|
||||
def get_user(id: str):
|
||||
return user_collect.get_items(
|
||||
TransactKey(id) + SortKey('0') + SortKey('last_profile_edit')
|
||||
)
|
||||
|
||||
|
||||
class Password(BaseModel):
|
||||
cognito_sub: UUID4
|
||||
new_password: Annotated[str, StringConstraints(min_length=6)]
|
||||
@@ -95,11 +138,6 @@ def password(id: str, payload: Password):
|
||||
)
|
||||
|
||||
|
||||
@router.get('/<id>', compress=True, tags=['User'], summary='Get user')
|
||||
def get_user(id: str):
|
||||
return user_collect.get_item(KeyPair(id, '0'))
|
||||
|
||||
|
||||
@router.get('/<sub>/idp', compress=True, include_in_schema=False)
|
||||
def get_idp(sub: str):
|
||||
return cognito.admin_get_user(
|
||||
|
||||
Reference in New Issue
Block a user