Pridani sitemap, fix flake
This commit is contained in:
@@ -6,9 +6,9 @@ from database.query_builder import QueryBuilder
|
||||
|
||||
class BaseDataloader:
|
||||
def __init__(
|
||||
self,
|
||||
model: Type[models.BaseModel],
|
||||
relationship_column, filters: Optional[list] = None
|
||||
self,
|
||||
model: Type[models.BaseModel],
|
||||
relationship_column, filters: Optional[list] = None
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.model = model
|
||||
@@ -39,12 +39,12 @@ class SingleModelByIdDataloader(BaseDataloader):
|
||||
|
||||
class MultiModelsDataloader(BaseDataloader):
|
||||
def __init__(
|
||||
self,
|
||||
model: Type[models.BaseModel],
|
||||
relationship_column=None,
|
||||
filters: Optional[list] = None,
|
||||
extra_join: Optional[list] = None,
|
||||
order_by: Optional[list] = None,
|
||||
self,
|
||||
model: Type[models.BaseModel],
|
||||
relationship_column=None,
|
||||
filters: Optional[list] = None,
|
||||
extra_join: Optional[list] = None,
|
||||
order_by: Optional[list] = None,
|
||||
):
|
||||
super().__init__(model, relationship_column, filters)
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ class AircraftQueries:
|
||||
@error_logging
|
||||
@allow_public
|
||||
async def aircraft(
|
||||
root, info,
|
||||
id: Optional[int] = None,
|
||||
call_sign: Optional[str] = None,
|
||||
public: Optional[bool] = False
|
||||
root, info,
|
||||
id: Optional[int] = None,
|
||||
call_sign: Optional[str] = None,
|
||||
public: Optional[bool] = False
|
||||
) -> Aircraft:
|
||||
filter_params = {}
|
||||
if id:
|
||||
|
||||
@@ -23,13 +23,12 @@ class CopilotQueries:
|
||||
@error_logging
|
||||
@allow_public
|
||||
async def copilot(
|
||||
root, info: Info,
|
||||
id: Optional[int] = None,
|
||||
url_slug: Optional[str] = None,
|
||||
pilot_username: Optional[str] = None,
|
||||
public: Optional[bool] = False
|
||||
root, info: Info,
|
||||
id: Optional[int] = None,
|
||||
url_slug: Optional[str] = None,
|
||||
pilot_username: Optional[str] = None,
|
||||
public: Optional[bool] = False
|
||||
) -> Copilot:
|
||||
|
||||
filter_params = get_detail_filters(id, url_slug)
|
||||
if pilot_username:
|
||||
filter_params['pilot_username'] = pilot_username
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import List, Optional
|
||||
from typing import Optional
|
||||
import strawberry
|
||||
from database import models
|
||||
from decorators.endpoints import authenticated_user_only, allow_public
|
||||
@@ -17,12 +17,12 @@ class EventQueries:
|
||||
@error_logging
|
||||
@allow_public
|
||||
async def events(
|
||||
root,
|
||||
info,
|
||||
limit: int,
|
||||
offset: int = 0,
|
||||
username: Optional[str] = None,
|
||||
public: Optional[bool] = False,
|
||||
root,
|
||||
info,
|
||||
limit: int,
|
||||
offset: int = 0,
|
||||
username: Optional[str] = None,
|
||||
public: Optional[bool] = False,
|
||||
) -> PaginationWindow[Event]:
|
||||
query = EventQueryResolver().get_query(
|
||||
info.context.user_id,
|
||||
@@ -42,11 +42,11 @@ class EventQueries:
|
||||
@error_logging
|
||||
@allow_public
|
||||
async def event(
|
||||
root, info,
|
||||
id: Optional[int] = None,
|
||||
url_slug: Optional[str] = None,
|
||||
username: Optional[str] = None,
|
||||
public: Optional[bool] = False
|
||||
root, info,
|
||||
id: Optional[int] = None,
|
||||
url_slug: Optional[str] = None,
|
||||
username: Optional[str] = None,
|
||||
public: Optional[bool] = False
|
||||
) -> Event:
|
||||
filter_params = get_detail_filters(id, url_slug)
|
||||
if username:
|
||||
|
||||
@@ -16,15 +16,15 @@ class FlightQueries:
|
||||
@error_logging
|
||||
@allow_public
|
||||
async def flights(
|
||||
root, info,
|
||||
limit: int,
|
||||
offset: int = 0,
|
||||
username: Optional[str] = None,
|
||||
event_id: Optional[int] = None,
|
||||
public: Optional[bool] = False,
|
||||
copilot_id: Optional[int] = None,
|
||||
point_of_interest_id: Optional[int] = None,
|
||||
aircraft_id: Optional[int] = None,
|
||||
root, info,
|
||||
limit: int,
|
||||
offset: int = 0,
|
||||
username: Optional[str] = None,
|
||||
event_id: Optional[int] = None,
|
||||
public: Optional[bool] = False,
|
||||
copilot_id: Optional[int] = None,
|
||||
point_of_interest_id: Optional[int] = None,
|
||||
aircraft_id: Optional[int] = None,
|
||||
) -> PaginationWindow[Flight]:
|
||||
query = FlightQueryResolver().get_query(
|
||||
user_id=info.context.user_id,
|
||||
@@ -47,11 +47,11 @@ class FlightQueries:
|
||||
@error_logging
|
||||
@allow_public
|
||||
async def flight(
|
||||
root, info,
|
||||
id: Optional[int] = None,
|
||||
url_slug: Optional[str] = None,
|
||||
username: Optional[str] = None,
|
||||
public: Optional[bool] = False
|
||||
root, info,
|
||||
id: Optional[int] = None,
|
||||
url_slug: Optional[str] = None,
|
||||
username: Optional[str] = None,
|
||||
public: Optional[bool] = False
|
||||
) -> Flight:
|
||||
filter_params = get_detail_filters(id, url_slug)
|
||||
if username:
|
||||
|
||||
@@ -5,12 +5,12 @@ from graphql_schema.entities.types.mutation_input import ComboboxInput
|
||||
|
||||
|
||||
async def handle_combobox_save(
|
||||
db: AsyncSession,
|
||||
model: Type[models.BaseModel],
|
||||
input: ComboboxInput,
|
||||
user_id: int,
|
||||
name_column: str = "name",
|
||||
extra_data: Optional[dict] = None
|
||||
db: AsyncSession,
|
||||
model: Type[models.BaseModel],
|
||||
input: ComboboxInput,
|
||||
user_id: int,
|
||||
name_column: str = "name",
|
||||
extra_data: Optional[dict] = None
|
||||
) -> int:
|
||||
if input.id:
|
||||
return input.id
|
||||
|
||||
@@ -18,10 +18,10 @@ class PaginationWindow(Generic[Item]):
|
||||
|
||||
|
||||
async def get_pagination_window(
|
||||
query: Select,
|
||||
item_type: type,
|
||||
limit: int,
|
||||
offset: int = 0,
|
||||
query: Select,
|
||||
item_type: type,
|
||||
limit: int,
|
||||
offset: int = 0,
|
||||
) -> PaginationWindow:
|
||||
if limit <= 0:
|
||||
raise Exception(f"limit ({limit}) must be > 0")
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from typing import List
|
||||
import strawberry
|
||||
from sqlalchemy import delete, select
|
||||
from sqlalchemy import delete
|
||||
from sqlalchemy.dialects.mysql import insert
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from database import models
|
||||
from decorators.endpoints import authenticated_user_only
|
||||
from database.transaction import get_session
|
||||
from decorators.error_logging import error_logging
|
||||
from graphql_schema.entities.resolvers.base import BaseQueryResolver, BaseMutationResolver
|
||||
from graphql_schema.entities.resolvers.base import BaseMutationResolver
|
||||
from graphql_schema.entities.resolvers.organization import OrganizationQueryResolver
|
||||
from graphql_schema.entities.types.mutation_input import CreateOrganizationInput, EditOrganizationInput
|
||||
from graphql_schema.entities.types.types import Organization
|
||||
|
||||
@@ -15,12 +15,12 @@ class PhotoQueries:
|
||||
@error_logging
|
||||
@allow_public
|
||||
async def photos(
|
||||
root, info,
|
||||
flight_id: Optional[int] = None,
|
||||
copilot_id: Optional[int] = None,
|
||||
point_of_interest_id: Optional[int] = None,
|
||||
aircraft_id: Optional[int] = None,
|
||||
public: Optional[bool] = False,
|
||||
root, info,
|
||||
flight_id: Optional[int] = None,
|
||||
copilot_id: Optional[int] = None,
|
||||
point_of_interest_id: Optional[int] = None,
|
||||
aircraft_id: Optional[int] = None,
|
||||
public: Optional[bool] = False,
|
||||
) -> List[Photo]:
|
||||
return await PhotoQueryResolver().get_list(
|
||||
public=public,
|
||||
@@ -35,7 +35,7 @@ class PhotoQueries:
|
||||
@strawberry.field()
|
||||
@error_logging
|
||||
@allow_public
|
||||
async def photo(root, info, id: int, public: Optional[bool] = False,) -> Photo:
|
||||
async def photo(root, info, id: int, public: Optional[bool] = False, ) -> Photo:
|
||||
return await BaseQueryResolver(Photo, models.Photo).get_one(
|
||||
object_id=id,
|
||||
user_id=info.context.user_id,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from typing import List, Optional
|
||||
from typing import Optional
|
||||
import strawberry
|
||||
from graphql import GraphQLError
|
||||
|
||||
from database import models
|
||||
from decorators.endpoints import authenticated_user_only, allow_public
|
||||
from database.transaction import get_session
|
||||
@@ -13,19 +11,24 @@ from graphql_schema.entities.resolvers.base import BaseQueryResolver, BaseMutati
|
||||
from graphql_schema.entities.types.types import PointOfInterest
|
||||
from graphql_schema.entities.types.mutation_input import CreatePointOfInterestInput, EditPointOfInterestInput
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class PointOfInterestQueries:
|
||||
@strawberry.field()
|
||||
@error_logging
|
||||
@allow_public
|
||||
async def points_of_interest(
|
||||
root, info,
|
||||
limit: int, offset: int = 0,
|
||||
search: Optional[str] = None,
|
||||
public: bool = False
|
||||
root, info,
|
||||
limit: int, offset: int = 0,
|
||||
search: Optional[str] = None,
|
||||
public: bool = False
|
||||
) -> PaginationWindow[PointOfInterest]:
|
||||
query = BaseQueryResolver(PointOfInterest, models.PointOfInterest).get_query(
|
||||
info.context.user_id, only_public=public, search=search,
|
||||
info.context.user_id,
|
||||
only_my=bool(info.context.user_id),
|
||||
include_others_public=True,
|
||||
only_public=public,
|
||||
search=search,
|
||||
)
|
||||
return await get_pagination_window(
|
||||
query=query,
|
||||
@@ -37,10 +40,10 @@ class PointOfInterestQueries:
|
||||
@strawberry.field()
|
||||
@allow_public
|
||||
async def point_of_interest(
|
||||
root, info,
|
||||
url_slug: Optional[str] = None,
|
||||
id: Optional[int] = None,
|
||||
public: bool = False
|
||||
root, info,
|
||||
url_slug: Optional[str] = None,
|
||||
id: Optional[int] = None,
|
||||
public: bool = False
|
||||
) -> PointOfInterest:
|
||||
filter_params = get_detail_filters(id, url_slug)
|
||||
|
||||
|
||||
@@ -16,13 +16,13 @@ class AircraftQueryResolver(BaseQueryResolver):
|
||||
super().__init__(graphql_type=Aircraft, model=models.Aircraft)
|
||||
|
||||
def get_query(
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
object_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
organization_ids: Optional[Set[int]] = None,
|
||||
*args,
|
||||
**kwargs,
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
object_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
organization_ids: Optional[Set[int]] = None,
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
filters = {}
|
||||
if object_id:
|
||||
|
||||
@@ -30,19 +30,21 @@ class BaseQueryResolver(BaseResolver):
|
||||
return self.graphql_type(**data.as_dict())
|
||||
|
||||
def get_query(
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
object_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
only_public: Optional[bool] = False,
|
||||
only_my: Optional[bool] = False,
|
||||
url_slug: Optional[str] = None,
|
||||
**kwargs,
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
object_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
only_public: Optional[bool] = False,
|
||||
only_my: Optional[bool] = False,
|
||||
include_others_public: Optional[bool] = False,
|
||||
url_slug: Optional[str] = None,
|
||||
**kwargs,
|
||||
):
|
||||
query = self.query_builder.get_simple_query(
|
||||
created_by_id=user_id,
|
||||
order_by=order_by,
|
||||
only_public=only_public,
|
||||
include_others_public=include_others_public,
|
||||
only_my=only_my,
|
||||
url_slug=url_slug
|
||||
)
|
||||
|
||||
@@ -9,12 +9,12 @@ class CopilotQueryResolver(BaseQueryResolver):
|
||||
super().__init__(Copilot, models.Copilot)
|
||||
|
||||
def get_query(
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
object_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
only_public: Optional[bool] = False,
|
||||
**kwargs
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
object_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
only_public: Optional[bool] = False,
|
||||
**kwargs
|
||||
):
|
||||
pilot_username = kwargs.pop("pilot_username", None)
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ class EventQueryResolver(BaseQueryResolver):
|
||||
super().__init__(graphql_type=Event, model=models.Event)
|
||||
|
||||
def get_query(
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
object_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
only_public: Optional[bool] = True,
|
||||
*args,
|
||||
**kwargs,
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
object_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
only_public: Optional[bool] = True,
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
query = super().get_query(
|
||||
user_id, object_id,
|
||||
|
||||
@@ -10,8 +10,10 @@ from database.models import flight_has_copilot
|
||||
from database.transaction import get_session
|
||||
from external.gpx_parser import GPXParser
|
||||
from graphql_schema.entities.helpers.combobox import handle_combobox_save
|
||||
from graphql_schema.entities.resolvers.base import BaseMutationResolver, BaseQueryResolver, GQL_TYPE
|
||||
from graphql_schema.entities.types.mutation_input import EditFlightInput, TrackItemInput, ComboboxInput, CreateFlightInput
|
||||
from graphql_schema.entities.resolvers.base import BaseMutationResolver, BaseQueryResolver
|
||||
from graphql_schema.entities.types.mutation_input import (
|
||||
EditFlightInput, TrackItemInput, ComboboxInput, CreateFlightInput
|
||||
)
|
||||
from graphql_schema.entities.types.types import Flight
|
||||
from paths import FLIGHT_GPX_TRACK_PATH
|
||||
from utils.file import delete_file
|
||||
@@ -23,13 +25,13 @@ class FlightQueryResolver(BaseQueryResolver):
|
||||
super().__init__(graphql_type=Flight, model=models.Flight)
|
||||
|
||||
def get_query(
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
object_id: Optional[int] = None,
|
||||
url_slug: Optional[str] = None,
|
||||
only_public: Optional[bool] = False,
|
||||
*args,
|
||||
**kwargs
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
object_id: Optional[int] = None,
|
||||
url_slug: Optional[str] = None,
|
||||
only_public: Optional[bool] = False,
|
||||
*args,
|
||||
**kwargs
|
||||
):
|
||||
filters = {}
|
||||
if object_id:
|
||||
@@ -77,20 +79,22 @@ class FlightMutationResolver(BaseMutationResolver):
|
||||
super().__init__(Flight, models.Flight)
|
||||
|
||||
async def get_airport_id_by_gps(self, gps_lat: float, gps_lng: float) -> Optional[int]:
|
||||
async with get_session() as db:
|
||||
query = select(
|
||||
models.Airport,
|
||||
func.coalesce((6371 * func.acos(
|
||||
async with (get_session() as db):
|
||||
query = (
|
||||
select(models.Airport, func.coalesce(6371 * func.acos(
|
||||
func.cos(func.radians(gps_lat)) *
|
||||
func.cos(func.radians(models.Airport.gps_latitude)) *
|
||||
func.cos(func.radians(models.Airport.gps_longitude) - func.radians(gps_lng)) +
|
||||
func.sin(func.radians(gps_lat)) *
|
||||
func.sin(func.radians(models.Airport.gps_latitude))
|
||||
)), 9999).label("distance")
|
||||
).filter(models.Airport.use_in_gpx_guess.is_(True)).order_by("distance").having(text("distance < 1")).limit(1)
|
||||
), 9999).label("distance"))
|
||||
.filter(models.Airport.use_in_gpx_guess.is_(True))
|
||||
.order_by("distance")
|
||||
.having(text("distance < 1"))
|
||||
.limit(1)
|
||||
)
|
||||
|
||||
data = (await db.execute(query)).one_or_none()
|
||||
|
||||
if data:
|
||||
airport, distance = data
|
||||
return airport.id
|
||||
@@ -151,11 +155,13 @@ class FlightMutationResolver(BaseMutationResolver):
|
||||
|
||||
context.background_tasks.add_task(
|
||||
download_weather,
|
||||
flight_id=flight.id, airport_id=flight.takeoff_airport_id, date_time=flight.takeoff_datetime, type_="takeoff"
|
||||
flight_id=flight.id, airport_id=flight.takeoff_airport_id, date_time=flight.takeoff_datetime,
|
||||
type_="takeoff"
|
||||
)
|
||||
context.background_tasks.add_task(
|
||||
download_weather,
|
||||
flight_id=flight.id, airport_id=flight.landing_airport_id, date_time=flight.landing_datetime, type_="landing"
|
||||
flight_id=flight.id, airport_id=flight.landing_airport_id, date_time=flight.landing_datetime,
|
||||
type_="landing"
|
||||
)
|
||||
|
||||
return flight
|
||||
|
||||
@@ -11,11 +11,11 @@ class OrganizationQueryResolver(BaseQueryResolver):
|
||||
super().__init__(Organization, models.Organization)
|
||||
|
||||
def get_query(
|
||||
self,
|
||||
object_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
**kwargs):
|
||||
|
||||
self,
|
||||
object_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
**kwargs
|
||||
):
|
||||
query = (
|
||||
select(models.Organization)
|
||||
.filter(models.Organization.deleted.is_(False))
|
||||
|
||||
@@ -25,12 +25,12 @@ class PhotoQueryResolver(BaseQueryResolver):
|
||||
super().__init__(Photo, models.Photo)
|
||||
|
||||
def get_query(
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
object_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
only_public: Optional[bool] = False,
|
||||
*args, **kwargs
|
||||
self,
|
||||
user_id: Optional[int] = None,
|
||||
object_id: Optional[int] = None,
|
||||
order_by: Optional[list] = None,
|
||||
only_public: Optional[bool] = False,
|
||||
*args, **kwargs
|
||||
):
|
||||
|
||||
query = super().get_query(
|
||||
@@ -80,7 +80,7 @@ class PhotoMutationResolver(BaseMutationResolver):
|
||||
async with get_session() as db:
|
||||
photo = await self._get_one(db, id, created_by_id=user_id)
|
||||
flight_id = photo.flight_id
|
||||
filename = photo.filename+"."+photo.filename_extension
|
||||
filename = photo.filename + "." + photo.filename_extension
|
||||
|
||||
path = get_photo_basepath(flight_id)
|
||||
return PhotoDetailInfo(
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
from __future__ import annotations
|
||||
from datetime import datetime
|
||||
from typing import Optional, List, Any
|
||||
from typing import Optional, List
|
||||
import strawberry
|
||||
from graphql import GraphQLError
|
||||
from strawberry.permission import PermissionExtension, BasePermission
|
||||
from strawberry.types import Info
|
||||
|
||||
from database import models
|
||||
from decorators.endpoints import authenticated_user_only
|
||||
from external.gpx_parser import GPXParser
|
||||
|
||||
@@ -44,9 +44,10 @@ def strawberry_sqlalchemy_type(model, exclude_fields: Optional[typing.Union[List
|
||||
|
||||
|
||||
def strawberry_sqlalchemy_input(
|
||||
model,
|
||||
exclude_fields: Optional[typing.Union[List, typing.Tuple]] = None,
|
||||
all_optional: bool = False) -> typing.Callable[[...], strawberry.object_type]:
|
||||
model,
|
||||
exclude_fields: Optional[typing.Union[List, typing.Tuple]] = None,
|
||||
all_optional: bool = False
|
||||
) -> typing.Callable[[...], strawberry.object_type]:
|
||||
if exclude_fields is None:
|
||||
exclude_fields = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user