Advertisement
Mochinov

Untitled

Nov 14th, 2022
947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1.  
  2. class Application(HTTPEndpoint):
  3.  
  4.     async def get(self, request: Request) -> JSONResponse:
  5.  
  6.         query = await async_session().execute(
  7.             select(Applications).options()
  8.         )
  9.         json_data = Serializer(
  10.             data=query.scalars().all(),
  11.         )
  12.         return JSONResponse(json_data.data)
  13.  
  14.     async def delete(self, request: Request) -> JSONResponse:
  15.         application_id = request.path_params.get("id")
  16.         if application_id:
  17.             query = Applications.__table__.update().where(Applications.id==application_id).values(
  18.                 state=Applications.ApplicationStateType.BLOCKED.name,
  19.                 deleted=True,
  20.             )
  21.             query.execution_options(synchronize_session="fetch")
  22.             await async_session().execute(query)
  23.             await async_session().commit()
  24.             await async_session().close()
  25.  
  26.         return JSONResponse(HTTP_204_NO_CONTENT)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement