86 lines
2.7 KiB
Python
86 lines
2.7 KiB
Python
from typing import Optional
|
|
import strawberry
|
|
from decorators.endpoints import authenticated_user_only, allow_public
|
|
from decorators.error_logging import error_logging
|
|
from graphql_schema.entities.resolvers.flight import FlightMutationResolver, FlightQueryResolver
|
|
from graphql_schema.entities.types.mutation_input import EditFlightInput, CreateFlightInput
|
|
from graphql_schema.entities.types.types import Flight
|
|
from .helpers.detail import get_detail_filters
|
|
from .helpers.pagination import PaginationWindow, get_pagination_window
|
|
|
|
|
|
@strawberry.type
|
|
class FlightQueries:
|
|
|
|
@strawberry.field()
|
|
@error_logging
|
|
@allow_public
|
|
async def flights(
|
|
root, info,
|
|
limit: int,
|
|
offset: int = 0,
|
|
username: str | None = None,
|
|
event_id: int | None = None,
|
|
public: bool | None = False,
|
|
copilot_id: int | None = None,
|
|
point_of_interest_id: int | None = None,
|
|
aircraft_id: int | None = None,
|
|
) -> PaginationWindow[Flight]:
|
|
query = FlightQueryResolver().get_query(
|
|
user_id=info.context.user_id,
|
|
username=username,
|
|
event_id=event_id,
|
|
only_public=public,
|
|
copilot_id=copilot_id,
|
|
aircraft_id=aircraft_id,
|
|
point_of_interest_id=point_of_interest_id
|
|
)
|
|
|
|
return await get_pagination_window(
|
|
query=query,
|
|
item_type=Flight,
|
|
limit=limit,
|
|
offset=offset,
|
|
)
|
|
|
|
@strawberry.field()
|
|
@error_logging
|
|
@allow_public
|
|
async def flight(
|
|
root, info,
|
|
id: int | None = None,
|
|
url_slug: str | None = None,
|
|
username: str | None = None,
|
|
public: bool | None = False
|
|
) -> Flight:
|
|
filter_params = get_detail_filters(id, url_slug)
|
|
if username:
|
|
filter_params['username'] = username
|
|
|
|
return await FlightQueryResolver().get_one(
|
|
user_id=info.context.user_id,
|
|
only_public=public,
|
|
**filter_params
|
|
)
|
|
|
|
|
|
@strawberry.type
|
|
class FlightMutation:
|
|
@strawberry.mutation
|
|
@error_logging
|
|
@authenticated_user_only()
|
|
async def create_flight(self, info, input: CreateFlightInput) -> Flight:
|
|
return await FlightMutationResolver().create(info.context, input)
|
|
|
|
@strawberry.mutation
|
|
@error_logging
|
|
@authenticated_user_only()
|
|
async def edit_flight(self, info, id: int, input: EditFlightInput) -> Flight:
|
|
return await FlightMutationResolver().update(info.context, id, input)
|
|
|
|
@strawberry.mutation
|
|
@error_logging
|
|
@authenticated_user_only()
|
|
async def delete_flight(self, info, id: int) -> Flight:
|
|
return await FlightMutationResolver().delete(info.context.user_id, id)
|