fastlane / routes /account_management.py
hrguarinv's picture
Update routes/account_management.py
89d2f5f verified
raw
history blame
1.26 kB
from fastapi import APIRouter, status, HTTPException
from models.input import Input
from services.elasticsearch import get_customer, update_customer
router = APIRouter()
@router.post("/sign-in-up")
def handle_sign_in_up(input: Input):
customer_id = next(
(entity['value'] for entity in input.entities if entity['entity'] == 'customer_id'), None)
if customer_id:
customer = get_customer(customer_id)
if not customer:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Customer not found")
return customer
else:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Customer ID not provided.")
@router.post("/update-account")
def handle_update_account(input: Input):
customer_id = next(
(entity['value'] for entity in input.entities if entity['entity'] == 'customer_id'), None)
updates = {entity['entity']: entity['value'] for entity in input.entities}
if customer_id:
update_customer(customer_id, updates)
return {"message": "Account information updated successfully"}
else:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Customer ID not provided.")