Uprava vycitani a nastavovani copilota
This commit is contained in:
@@ -13,5 +13,5 @@ class CopilotType:
|
|||||||
@strawberry.type
|
@strawberry.type
|
||||||
class CopilotQueries:
|
class CopilotQueries:
|
||||||
@strawberry.field
|
@strawberry.field
|
||||||
async def pilots(root, info) -> List[CopilotType]:
|
async def copilots(root, info) -> List[CopilotType]:
|
||||||
return (await info.context['db'].scalars(select(Copilot))).all()
|
return (await info.context.db.scalars(select(Copilot))).all()
|
||||||
|
|||||||
@@ -161,8 +161,19 @@ async def handle_track_edit(db: AsyncSession, flight: models.Flight, track: List
|
|||||||
order += 1
|
order += 1
|
||||||
|
|
||||||
|
|
||||||
def handle_copilot_edit():
|
async def handle_copilot_edit(db: AsyncSession, copilot: CopilotInput, user_id: int) -> int:
|
||||||
pass
|
if copilot.id:
|
||||||
|
return copilot.id
|
||||||
|
else:
|
||||||
|
copilot = await models.Copilot.create(
|
||||||
|
db,
|
||||||
|
data={
|
||||||
|
"name": copilot.name,
|
||||||
|
"created_by_id": user_id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
await db.flush()
|
||||||
|
return copilot.id
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
@@ -179,18 +190,9 @@ class EditFlightMutation:
|
|||||||
if input.track is not None:
|
if input.track is not None:
|
||||||
await handle_track_edit(db=info.context.db, flight=flight, track=input.track, user_id=info.context.user_id)
|
await handle_track_edit(db=info.context.db, flight=flight, track=input.track, user_id=info.context.user_id)
|
||||||
|
|
||||||
if input.copilot is not None and not flight.solo:
|
if flight.solo:
|
||||||
if input.copilot.id:
|
flight.copilot_id = None
|
||||||
flight.copilot_id = input.copilot.id
|
elif input.copilot is not None:
|
||||||
else:
|
flight.copilot_id = await handle_copilot_edit(info.context.db, input.copilot, info.context.user_id)
|
||||||
copilot = await models.Copilot.create(
|
|
||||||
info.context.db,
|
|
||||||
data={
|
|
||||||
"created_by_id": info.context.user_id,
|
|
||||||
"name": input.copilot.name
|
|
||||||
}
|
|
||||||
)
|
|
||||||
info.context.db.flush()
|
|
||||||
flight.copilot_id = copilot.id
|
|
||||||
|
|
||||||
return flight
|
return flight
|
||||||
|
|||||||
+4
-1
@@ -1,9 +1,10 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from fastapi import FastAPI, APIRouter, Depends, Security
|
from fastapi import FastAPI, APIRouter, Depends, Security, HTTPException
|
||||||
from fastapi_jwt import JwtAuthorizationCredentials, JwtAccessBearerCookie, JwtRefreshBearerCookie
|
from fastapi_jwt import JwtAuthorizationCredentials, JwtAccessBearerCookie, JwtRefreshBearerCookie
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
from starlette.middleware.cors import CORSMiddleware
|
from starlette.middleware.cors import CORSMiddleware
|
||||||
from starlette.responses import RedirectResponse, Response
|
from starlette.responses import RedirectResponse, Response
|
||||||
|
from starlette.status import HTTP_401_UNAUTHORIZED
|
||||||
from strawberry.fastapi import GraphQLRouter
|
from strawberry.fastapi import GraphQLRouter
|
||||||
from config import APP_SECRET_KEY, GRAPHIQL, APP_DEBUG
|
from config import APP_SECRET_KEY, GRAPHIQL, APP_DEBUG
|
||||||
from dependencies.db import db_session
|
from dependencies.db import db_session
|
||||||
@@ -63,6 +64,8 @@ class App:
|
|||||||
credentials: JwtAuthorizationCredentials = Security(self.access_security),
|
credentials: JwtAuthorizationCredentials = Security(self.access_security),
|
||||||
db: AsyncSession = Depends(db_session),
|
db: AsyncSession = Depends(db_session),
|
||||||
):
|
):
|
||||||
|
if not credentials:
|
||||||
|
raise HTTPException(status_code=HTTP_401_UNAUTHORIZED)
|
||||||
|
|
||||||
return GraphQLContext(
|
return GraphQLContext(
|
||||||
jwt_auth_credentials=credentials,
|
jwt_auth_credentials=credentials,
|
||||||
|
|||||||
Reference in New Issue
Block a user