File size: 963 Bytes
df37f6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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