dialogflowAPI / app /resolvers /location_resolver.py
OnlyBiggg
refactor code
df37f6e
from typing import Literal, Optional
from fastapi.params import Depends
from typing_extensions import Annotated
from app.services.location_service import LocationService
from app.resolvers.origin_code import get_city_id_and_code
class LocationResolver:
def __init__(self, location_service: LocationService):
self.location_service = location_service
async def resolve_info(
self,
office: Optional[str],
city: Optional[str],
role: Literal["origin", "dest"],
) -> tuple[Optional[int], Optional[str], Optional[int]]:
if office:
id, code, _ = await self.location_service.get_city_by_office(
office_name=office, role=role
)
ids = await self.location_service.get_office_id_by_name(office)
return id, code, ids
if city:
id, code = get_city_id_and_code(city)
return id, code, None
return None, None, None