uprava letu
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
"""flight duration
|
||||||
|
|
||||||
|
Revision ID: 419cf23cbf83
|
||||||
|
Revises: 559795b043f3
|
||||||
|
Create Date: 2023-06-06 17:41:26.375394
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import mysql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '419cf23cbf83'
|
||||||
|
down_revision = '559795b043f3'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('flight', sa.Column('duration_total', sa.Integer(), nullable=True))
|
||||||
|
op.alter_column('flight', 'duration_pic',
|
||||||
|
existing_type=mysql.INTEGER(display_width=11),
|
||||||
|
nullable=True)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.alter_column('flight', 'duration_pic',
|
||||||
|
existing_type=mysql.INTEGER(display_width=11),
|
||||||
|
nullable=False)
|
||||||
|
op.drop_column('flight', 'duration_total')
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -183,7 +183,8 @@ class Flight(BaseModel):
|
|||||||
description: Mapped[str] = mapped_column(Text, nullable=False)
|
description: Mapped[str] = mapped_column(Text, nullable=False)
|
||||||
takeoff_datetime: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
takeoff_datetime: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||||
landing_datetime: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
landing_datetime: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
||||||
duration_pic: Mapped[int] = mapped_column(Integer, nullable=False)
|
duration_total: Mapped[int] = mapped_column(Integer, nullable=True)
|
||||||
|
duration_pic: Mapped[int] = mapped_column(Integer, nullable=True)
|
||||||
takeoff_airport_id: Mapped[int] = mapped_column(Integer, ForeignKey("airport.id"), nullable=True)
|
takeoff_airport_id: Mapped[int] = mapped_column(Integer, ForeignKey("airport.id"), nullable=True)
|
||||||
landing_airport_id: Mapped[int] = mapped_column(Integer, ForeignKey("airport.id"), nullable=True)
|
landing_airport_id: Mapped[int] = mapped_column(Integer, ForeignKey("airport.id"), nullable=True)
|
||||||
aircraft_id: Mapped[int] = mapped_column(Integer, ForeignKey('aircraft.id'))
|
aircraft_id: Mapped[int] = mapped_column(Integer, ForeignKey('aircraft.id'))
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from datetime import timedelta
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
import strawberry
|
import strawberry
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
@@ -29,11 +30,21 @@ class Flight:
|
|||||||
async def load_copilot(root):
|
async def load_copilot(root):
|
||||||
return await copilots_dataloader.load(root.copilot_id)
|
return await copilots_dataloader.load(root.copilot_id)
|
||||||
|
|
||||||
|
def duration_min_calculated(root):
|
||||||
|
if root.duration_total:
|
||||||
|
return root.duration_total
|
||||||
|
|
||||||
|
if root.takeoff_datetime and root.landing_datetime:
|
||||||
|
diff: timedelta = root.landing_datetime - root.takeoff_datetime
|
||||||
|
return diff.seconds / 60
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
duration_min_calculated: int = strawberry.field(resolver=duration_min_calculated)
|
||||||
copilot: Optional[CopilotType] = strawberry.field(resolver=load_copilot)
|
copilot: Optional[CopilotType] = strawberry.field(resolver=load_copilot)
|
||||||
aircraft: Aircraft = strawberry.field(resolver=load_aircraft)
|
aircraft: Aircraft = strawberry.field(resolver=load_aircraft)
|
||||||
takeoff_airport: Airport = strawberry.field(resolver=load_takeoff_airport)
|
takeoff_airport: Airport = strawberry.field(resolver=load_takeoff_airport)
|
||||||
landing_airport: Airport = strawberry.field(resolver=load_landing_airport)
|
landing_airport: Airport = strawberry.field(resolver=load_landing_airport)
|
||||||
# take_off_airport = Airport
|
|
||||||
|
|
||||||
|
|
||||||
def get_base_query(user_id: int):
|
def get_base_query(user_id: int):
|
||||||
@@ -61,8 +72,9 @@ class FlightQueries:
|
|||||||
query = (
|
query = (
|
||||||
get_base_query(info.context.user_id)
|
get_base_query(info.context.user_id)
|
||||||
.filter(models.Flight.id == id)
|
.filter(models.Flight.id == id)
|
||||||
|
.filter(models.Flight.deleted.is_(False))
|
||||||
)
|
)
|
||||||
return (await info.context.db.scalars(query)).fetch_one()
|
return (await info.context.db.scalars(query)).one()
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
|
|||||||
Reference in New Issue
Block a user