Priprava modelu na GPX v DB
This commit is contained in:
@@ -1,19 +1,48 @@
|
||||
import asyncio
|
||||
|
||||
from typing import Optional
|
||||
from sqlalchemy import delete, select
|
||||
from sqlalchemy.dialects.mysql import insert
|
||||
|
||||
from database import models
|
||||
from database.models import flight_plan_has_copilot
|
||||
from database.transaction import get_session
|
||||
from graphql_schema.entities.helpers.combobox import handle_combobox_save
|
||||
from graphql_schema.entities.resolvers.base import BaseMutationResolver
|
||||
from graphql_schema.entities.resolvers.base import BaseMutationResolver, BaseQueryResolver
|
||||
from graphql_schema.entities.resolvers.flight import handle_aircraft_save
|
||||
from graphql_schema.entities.types.mutation_input import CreateFlightPlanInput, EditFlightPlanInput
|
||||
from graphql_schema.entities.types.types import FlightPlan
|
||||
from utils.str_utils import random_str
|
||||
|
||||
|
||||
class FlightPlanQueryResolver(BaseQueryResolver):
|
||||
def __init__(self):
|
||||
super().__init__(graphql_type=FlightPlan, model=models.FlightPlan)
|
||||
|
||||
def get_query(
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
only_public: Optional[bool] = False,
|
||||
object_id: Optional[int] = None,
|
||||
*args,
|
||||
**kwargs
|
||||
):
|
||||
filters = {"object_id": object_id} if object_id else {}
|
||||
|
||||
query = super().get_query(
|
||||
user_id,
|
||||
**filters,
|
||||
order_by=[models.FlightPlan.planned_takeoff_datetime.desc(), models.FlightPlan.id.desc()],
|
||||
only_public=only_public,
|
||||
only_my=not only_public
|
||||
)
|
||||
if kwargs.get('username'):
|
||||
query = (
|
||||
query.join(models.FlightPlan.created_by)
|
||||
.filter(models.User.public_username == kwargs['username'])
|
||||
)
|
||||
|
||||
return query
|
||||
|
||||
|
||||
class FlightPlanMutationResolver(BaseMutationResolver):
|
||||
def __init__(self):
|
||||
super().__init__(graphql_type=FlightPlan, model=models.FlightPlan)
|
||||
@@ -100,4 +129,4 @@ def evenly_spaced_elements(lst: list, count: int) -> list:
|
||||
if count > len(lst):
|
||||
return lst
|
||||
interval = (len(lst) - 1) / (count - 1) if count > 1 else 0
|
||||
return [lst[int(round(i * interval))] for i in range(count)]
|
||||
return [lst[int(round(i * interval))] for i in range(count)]
|
||||
|
||||
Reference in New Issue
Block a user