update address
This commit is contained in:
51
http-api/app/routes/orgs/address.py
Normal file
51
http-api/app/routes/orgs/address.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from http import HTTPStatus
|
||||
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from layercake.dynamodb import (
|
||||
DynamoDBPersistenceLayer,
|
||||
KeyPair,
|
||||
)
|
||||
from pydantic import BaseModel
|
||||
|
||||
from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client
|
||||
from config import USER_TABLE
|
||||
|
||||
router = Router()
|
||||
org_layer = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@router.get(
|
||||
'/<id>/address',
|
||||
compress=True,
|
||||
tags=['Organization'],
|
||||
summary='Get organization address',
|
||||
)
|
||||
def get_address(id: str):
|
||||
return org_layer.collection.get_item(
|
||||
KeyPair(id, 'metadata#address'),
|
||||
)
|
||||
|
||||
|
||||
class Address(BaseModel):
|
||||
postcode: str
|
||||
address1: str
|
||||
address2: str | None = None
|
||||
neighborhood: str
|
||||
city: str
|
||||
state: str
|
||||
|
||||
|
||||
@router.post('/<id>/address', compress=True, tags=['Organization'])
|
||||
def post_address(id: str, payload: Address):
|
||||
address = payload.model_dump()
|
||||
org_layer.collection.put_item(
|
||||
key=KeyPair(id, 'metadata#address'),
|
||||
cond_expr='attribute_exists(sk)',
|
||||
**address,
|
||||
)
|
||||
|
||||
return JSONResponse(
|
||||
body=payload,
|
||||
status_code=HTTPStatus.OK,
|
||||
)
|
||||
Reference in New Issue
Block a user