Spaces:
Sleeping
Sleeping
| from fastapi import Depends | |
| from trauma.api.account.dto import AccountType | |
| from trauma.api.account.model import AccountModel | |
| from trauma.api.common.dto import Paging | |
| from trauma.api.data import facility_router | |
| from trauma.api.data.db_requests import get_facility_by_id, get_all_model_obj, search_facilities_obj | |
| from trauma.api.data.model import EntityModel | |
| from trauma.api.data.schemas import AllFacilitiesWrapper, AllFacilitiesResponse, SearchRequest | |
| from trauma.core.security import PermissionDependency | |
| from trauma.core.wrappers import TraumaResponseWrapper | |
| async def get_all_countries( | |
| _: AccountModel = Depends(PermissionDependency([AccountType.Admin, AccountType.User])) | |
| ) -> AllFacilitiesWrapper: | |
| all_facilities = await get_all_model_obj() | |
| response = AllFacilitiesResponse( | |
| paging=Paging(pageSize=len(all_facilities), pageIndex=0, totalCount=len(all_facilities)), | |
| data=all_facilities | |
| ) | |
| return AllFacilitiesWrapper(data=response) | |
| async def search_facilities( | |
| data: SearchRequest, | |
| ) -> AllFacilitiesWrapper: | |
| countries, total_count = await search_facilities_obj(data) | |
| response = AllFacilitiesResponse( | |
| paging=Paging(pageSize=data.pageSize, pageIndex=data.pageIndex, totalCount=total_count), | |
| data=countries | |
| ) | |
| return AllFacilitiesWrapper(data=response) | |
| async def get_country( | |
| facilityId: str, | |
| _: AccountModel = Depends(PermissionDependency([AccountType.Admin, AccountType.User])) | |
| ) -> TraumaResponseWrapper[EntityModel]: | |
| facility = await get_facility_by_id(facilityId) | |
| return TraumaResponseWrapper(data=facility) | |