Slide 16
Slide 16 text
Код для list view (list, create)
async def get(
self,
query_params: InvitationQueryStringManager = Depends(InvitationQueryStringManager),
session: AsyncSession = Depends(get_as_session),
account: Account = Depends(get_target_account_from_query_or_auth_account),
_: bool = Depends(permissions_get_list),
) -> Union[Select, JSONAPIResultListSchema]:
invitation_query = select(
# get invitations
Invitation,
).where(
# auth or target account
Invitation.account_id
== account.id,
)
dl = SqlalchemyEngine(
schema=self.jsonapi.schema_list,
model=self.jsonapi.model,
session=session,
query=invitation_query,
)
return await self.get_paginated_result(
dl=dl,
query_params=query_params,
)
async def post(
self,
query_params: QueryStringManager,
data_for_create: InvitationCreateSchema,
session: AsyncSession = Depends(get_as_session),
target_account: Account = Depends(get_target_account_from_jsonapi_body),
_: bool = Depends(permissions_create),
) -> JSONAPIResultDetailSchema:
invitation = await self.invitation_create(
data_for_create=data_for_create,
account_for_invitation=target_account,
session=session,
)
dl = SqlalchemyEngine(
schema=self.jsonapi.schema_detail,
model=self.jsonapi.model,
session=session,
)
view_kwargs = {'id': invitation.id}
return await self.get_detailed_result(
dl=dl,
view_kwargs=view_kwargs,
query_params=query_params,
) 11