fastlane / routes /account_management.py
Hugo Guarin
Update space
c169262
raw
history blame
1.26 kB
from fastapi import APIRouter, status, HTTPException
from models.query import Query
from services.elasticsearch import get_customer, update_customer
router = APIRouter()
@router.post("/sign-in-up")
def handle_sign_in_up(query: Query):
customer_id = next(
(entity['value'] for entity in query.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(query: Query):
customer_id = next(
(entity['value'] for entity in query.entities if entity['entity'] == 'customer_id'), None)
updates = {entity['entity']: entity['value'] for entity in query.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.")