2023-11-13 07:38:01 +03:00
|
|
|
from .helpers import grab_data
|
|
|
|
from core.registry import office_storage
|
|
|
|
from core.models.office.responses import JdeOfficeDetailResponse
|
|
|
|
from ...models.office.requests import UpdateOfficeRequest
|
|
|
|
|
|
|
|
|
|
|
|
async def list_offices_service() -> list[JdeOfficeDetailResponse]:
|
|
|
|
offices = await grab_data()
|
|
|
|
offices.sort(key=lambda x: x.code)
|
2023-11-15 16:20:07 +03:00
|
|
|
offices_additional_data = {data.code: data.model_dump() for data in office_storage.list_all_offices()}
|
2023-11-13 07:38:01 +03:00
|
|
|
response_data = [
|
|
|
|
JdeOfficeDetailResponse(**office.model_dump(), changeable_info=None or offices_additional_data.get(office.code)) for office in offices
|
|
|
|
]
|
|
|
|
|
|
|
|
return response_data
|
|
|
|
|
|
|
|
|
|
|
|
async def update_office(data: UpdateOfficeRequest):
|
|
|
|
office_storage.update_office(data)
|