Zaklad pro planovac letu

This commit is contained in:
Michal Kváček
2024-03-23 20:15:47 +01:00
parent ed35de96c9
commit 24825108a7
7 changed files with 133 additions and 0 deletions
@@ -0,0 +1,38 @@
"""add flight_plan table
Revision ID: 7a3738a805c5
Revises: aba4c3876b28
Create Date: 2024-03-21 16:42:08.428875
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '7a3738a805c5'
down_revision = 'aba4c3876b28'
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('flight_plan',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('markers', mysql.JSON(), nullable=False),
sa.Column('is_public', sa.Boolean(), server_default='0', nullable=False),
sa.Column('created_by_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
sa.Column('deleted', sa.Boolean(), server_default='0', nullable=False),
sa.ForeignKeyConstraint(['created_by_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('flight_plan')
# ### end Alembic commands ###
+14
View File
@@ -81,6 +81,20 @@ class AirspaceItem(BaseModel):
bounds: Mapped[list[tuple[float, float]]] = mapped_column(JSON())
class FlightPlan(BaseModel):
__tablename__ = "flight_plan"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(128), nullable=False)
markers: Mapped[dict] = mapped_column(JSON())
is_public: Mapped[bool] = mapped_column(Boolean, server_default='0')
created_by_id: Mapped[int] = mapped_column(Integer, ForeignKey('user.id'))
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
deleted: Mapped[bool] = mapped_column(Boolean, nullable=False, server_default='0')
created_by: Mapped['User'] = relationship()
class Airport(BaseModel):
__tablename__ = "airport"
@@ -0,0 +1,48 @@
from typing import List, Optional
import strawberry
from graphql import GraphQLError
from strawberry.types import Info
from database import models
from decorators.error_logging import error_logging
from decorators.endpoints import authenticated_user_only, allow_public
from graphql_schema.entities.resolvers.base import BaseMutationResolver, BaseQueryResolver
from graphql_schema.entities.types.mutation_input import CreateFlightPlanInput, EditFlightPlanInput
from graphql_schema.entities.types.types import FlightPlan
@strawberry.type
class FlightPlanQueries:
@strawberry.field()
@error_logging
@authenticated_user_only()
async def flight_plans(root, info: Info) -> List[FlightPlan]:
return await BaseQueryResolver(FlightPlan, models.FlightPlan).get_list(info.context.user_id)
@strawberry.field()
@error_logging
@allow_public
async def flight_plan(
root, info: Info,
id: Optional[int] = None,
public: Optional[bool] = False
) -> FlightPlan:
return await BaseQueryResolver(FlightPlan, models.FlightPlan).get_one(
user_id=info.context.user_id,
only_public=public,
object_id=id
)
@strawberry.type
class FlightPlanMutation:
@strawberry.mutation
@error_logging
@authenticated_user_only()
async def create_flight_plan(root, info, input: CreateFlightPlanInput) -> FlightPlan:
return await BaseMutationResolver(FlightPlan, models.FlightPlan).create(info.context, data=input)
@strawberry.mutation
@error_logging
@authenticated_user_only()
async def edit_flight_plan(root, info, id: int, input: EditFlightPlanInput) -> FlightPlan:
return await BaseMutationResolver(FlightPlan, models.FlightPlan).update(id, input, info.context.user_id)
@@ -14,11 +14,28 @@ class ComboboxInput:
name: str
@strawberry.input()
class FlightPlanMarkerInput:
name: str
gps_latitude: float
gps_longitude: float
@strawberry_sqlalchemy_input(model=models.Copilot, exclude_fields=["id"])
class CreateCopilotInput(BaseGraphqlInputType):
pass
@strawberry_sqlalchemy_input(model=models.FlightPlan, exclude_fields=["id", "markers"])
class CreateFlightPlanInput(BaseGraphqlInputType):
markers: list[FlightPlanMarkerInput]
@strawberry_sqlalchemy_input(model=models.FlightPlan, exclude_fields=["id", "markers"], all_optional=True)
class EditFlightPlanInput(BaseGraphqlInputType):
markers: list[FlightPlanMarkerInput]
@strawberry_sqlalchemy_input(model=models.Copilot, exclude_fields=["id"], all_optional=True)
class EditCopilotInput(BaseGraphqlInputType):
pass
@@ -180,6 +180,18 @@ class Flight:
)
@strawberry.type
class FlightPlanMarker:
name: str
gps_latitude: float
gps_longitude: float
@strawberry_sqlalchemy_type(models.FlightPlan, exclude_fields=["markers"])
class FlightPlan:
markers: list[FlightPlanMarker] = strawberry.field()
@strawberry_sqlalchemy_type(models.Copilot)
class Copilot:
async def resolve_flights(root, info):
+2
View File
@@ -3,6 +3,7 @@ from graphql_schema.entities.aircraft import AircraftMutation
from graphql_schema.entities.copilot import CopilotMutation
from graphql_schema.entities.event import EventMutation
from graphql_schema.entities.flight import FlightMutation
from graphql_schema.entities.flight_plan import FlightPlanMutation
from graphql_schema.entities.organization import OrganizationUserMutation, OrganizationMutation
from graphql_schema.entities.photo import PhotoMutation
from graphql_schema.entities.poi import PointOfInterestMutation
@@ -11,6 +12,7 @@ from graphql_schema.entities.user import EditUserMutation
Mutation = merge_types("Mutation", (
AircraftMutation,
FlightMutation,
FlightPlanMutation,
PhotoMutation,
PointOfInterestMutation,
CopilotMutation,
+2
View File
@@ -5,6 +5,7 @@ from .entities.airspace import AirspaceQueries
from .entities.copilot import CopilotQueries
from .entities.event import EventQueries
from .entities.flight import FlightQueries
from .entities.flight_plan import FlightPlanQueries
from .entities.organization import OrganizationQueries
from .entities.photo import PhotoQueries
from .entities.poi import PointOfInterestQueries
@@ -19,6 +20,7 @@ Query = merge_types('Query', (
AirportQueries,
AirspaceQueries,
FlightQueries,
FlightPlanQueries,
CopilotQueries,
UserQueries,
PhotoQueries,