Spaces:
Running
Running
File size: 1,957 Bytes
c6cc0f2 aabf8ec c6cc0f2 aabf8ec c6cc0f2 aabf8ec |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
from typing import Optional
from fastapi import Depends, Query
from trauma.api.account import account_router
from trauma.api.account.db_requests import get_all_model_obj, create_account_obj, delete_account
from trauma.api.account.dto import AccountType
from trauma.api.account.model import AccountModel
from trauma.api.account.schemas import AccountWrapper, AllAccountsResponse, CreateAccountRequest
from trauma.api.common.dto import Paging
from trauma.core.security import PermissionDependency
from trauma.core.wrappers import TraumaResponseWrapper
@account_router.get('/all')
async def get_all_accounts(
pageSize: Optional[int] = Query(10, description="Number of countries to return per page"),
pageIndex: Optional[int] = Query(0, description="Page index to retrieve"),
_: AccountModel = Depends(PermissionDependency([AccountType.Admin]))
) -> TraumaResponseWrapper[AllAccountsResponse]:
countries, total_count = await get_all_model_obj(pageSize, pageIndex)
response = AllAccountsResponse(
paging=Paging(pageSize=pageSize, pageIndex=pageIndex, totalCount=total_count),
data=countries
)
return TraumaResponseWrapper(data=response)
@account_router.get('')
async def get_account(
account: AccountModel = Depends(PermissionDependency([AccountType.Admin, AccountType.User]))
) -> AccountWrapper:
return AccountWrapper(data=account)
@account_router.post('')
async def create_account(
account_data: CreateAccountRequest,
_: AccountModel = Depends(PermissionDependency([AccountType.Admin]))
) -> AccountWrapper:
account = await create_account_obj(account_data)
return AccountWrapper(data=account)
@account_router.delete('/{accountId}')
async def update_account(
accountId: str,
_: AccountModel = Depends(PermissionDependency([AccountType.Admin]))
) -> TraumaResponseWrapper:
await delete_account(accountId)
return TraumaResponseWrapper()
|