Spaces:
Sleeping
Sleeping
| from loguru import logger | |
| from fastapi import APIRouter, Depends, HTTPException, Request | |
| from dependency_injector.wiring import inject, Provide | |
| from app.dependencies.containers import Container | |
| from app.dto.request import LocationRequest | |
| from app.dto.response import DialogFlowResponseAPI | |
| from app.services.location_service import LocationService | |
| router = APIRouter(prefix="/location", tags=["Location"]) | |
| async def get_origin_city_from_office( | |
| request: Request, | |
| service: LocationService = Depends(Provide[Container.location_service]), | |
| ): | |
| body = await request.json() | |
| params = body.get("sessionInfo", {}).get("parameters", {}) | |
| try: | |
| data = LocationRequest(**params) | |
| except Exception: | |
| logger.error("Invalid location parameters", exc_info=True) | |
| raise HTTPException(status_code=400, detail="Invalid location parameters") | |
| if data.origin_office and not data.departure_city: | |
| _, _, city = await service.get_city_by_office( | |
| office_name=data.origin_office, role="origin" | |
| ) | |
| return DialogFlowResponseAPI(parameters={"departure_city": city}) | |
| return DialogFlowResponseAPI(parameters={"departure_city": data.departure_city}) | |
| async def get_dest_city_from_office( | |
| request: Request, | |
| service: LocationService = Depends(Provide[Container.location_service]), | |
| ): | |
| body = await request.json() | |
| params = body.get("sessionInfo", {}).get("parameters", {}) | |
| try: | |
| data = LocationRequest.model_validate(params) | |
| except Exception: | |
| logger.error("Invalid location parameters", exc_info=True) | |
| raise HTTPException(status_code=400, detail="Invalid location parameters") | |
| if data.dest_office and not data.destination_city: | |
| city = await service.get_city_by_office( | |
| office_name=data.dest_office, role="dest" | |
| ) | |
| return DialogFlowResponseAPI(parameters={"destination_city": city}) | |
| return DialogFlowResponseAPI(parameters={"destination_city": data.destination_city}) | |