API pro podporu vytvareni letu z planu
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import asyncio
|
||||
import random
|
||||
import uuid
|
||||
from typing import List, Optional
|
||||
from sqlalchemy import delete, insert, select, func, text
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
@@ -142,12 +144,15 @@ class FlightMutationResolver(BaseMutationResolver):
|
||||
data.update({
|
||||
"aircraft_id": aircraft_id,
|
||||
"has_terrain_elevation": False,
|
||||
"name": "",
|
||||
"name": input.name or '',
|
||||
"description": "",
|
||||
"created_by_id": context.user_id
|
||||
})
|
||||
flight = await self._do_create(db, data)
|
||||
|
||||
if input.track is not None:
|
||||
await handle_track_edit(db=db, flight_id=flight.id, track=input.track, user_id=user_id)
|
||||
|
||||
context.background_tasks.add_task(
|
||||
download_weather_for_flight,
|
||||
flight_id=flight.id, airport_id=flight.takeoff_airport_id, date_time=flight.takeoff_datetime,
|
||||
@@ -256,14 +261,23 @@ async def handle_track_edit(db: AsyncSession, flight_id: int, track: List[TrackI
|
||||
|
||||
if item.point_of_interest:
|
||||
poi_id = await handle_combobox_save(
|
||||
db, models.PointOfInterest, item.point_of_interest, user_id, extra_data={"description": ""}
|
||||
db, models.PointOfInterest, item.point_of_interest, user_id, extra_data={
|
||||
"description": "",
|
||||
'gps_latitude': item.gps_latitude,
|
||||
'gps_longitude': item.gps_longitude
|
||||
}
|
||||
)
|
||||
|
||||
if item.airport:
|
||||
airport_id = await handle_combobox_save(
|
||||
db, models.Airport, item.airport, user_id,
|
||||
name_column="icao_code",
|
||||
extra_data={"name": item.airport.name}
|
||||
extra_data={
|
||||
"name": item.airport.name,
|
||||
'gps_latitude': item.gps_latitude,
|
||||
'gps_longitude': item.gps_longitude,
|
||||
'openaip_id': f'custom-{random.randint(0, 999999)}'
|
||||
}
|
||||
)
|
||||
|
||||
await models.FlightTrack.create(
|
||||
|
||||
@@ -52,9 +52,18 @@ class FlightPlanMutationResolver(BaseMutationResolver):
|
||||
position = 0
|
||||
|
||||
for marker in markers:
|
||||
|
||||
if marker.type == 'poi':
|
||||
assert bool(marker.point_of_interest_id)
|
||||
|
||||
if marker.type == 'airport':
|
||||
assert bool(marker.airport_id)
|
||||
|
||||
await models.FlightPlanMarker.create(db, data={
|
||||
"position": position,
|
||||
"flight_plan_id": flight_plan.id,
|
||||
"airport_id": marker.airport_id,
|
||||
"point_of_interest_id": marker.point_of_interest_id,
|
||||
"type": marker.type,
|
||||
"name": marker.name,
|
||||
"gps_latitude": marker.gps_latitude,
|
||||
|
||||
@@ -138,11 +138,14 @@ class EditFlightInput(BaseGraphqlInputType):
|
||||
@strawberry.input()
|
||||
class CreateFlightInput(BaseGraphqlInputType):
|
||||
aircraft: ComboboxInput
|
||||
flight_plan_id: Optional[int] = None
|
||||
name: Optional[str] = None
|
||||
gpx_track_file: Optional[Upload] = None # TODO: poresit validaci uploadovaneho souboru!
|
||||
landing_airport: Optional[ComboboxInput] = None
|
||||
takeoff_airport: Optional[ComboboxInput] = None
|
||||
takeoff_datetime: Optional[datetime] = None
|
||||
landing_datetime: Optional[datetime] = None
|
||||
track: Optional[List[TrackItemInput]] = None
|
||||
|
||||
|
||||
@strawberry.input()
|
||||
@@ -150,6 +153,8 @@ class TrackItemInput:
|
||||
point_of_interest: Optional[ComboboxInput] = None
|
||||
airport: Optional[ComboboxInput] = None
|
||||
landing_duration: Optional[int] = None
|
||||
gps_latitude: Optional[float] = None
|
||||
gps_longitude: Optional[float] = None
|
||||
|
||||
|
||||
@strawberry_sqlalchemy_input(models.Aircraft, exclude_fields=['id', 'photo_filename'])
|
||||
|
||||
Reference in New Issue
Block a user