Implement basic aircraft management
This commit is contained in:
@@ -3,6 +3,7 @@ import logging
|
||||
from bson import ObjectId
|
||||
|
||||
from app.config import get_settings
|
||||
from schemas.aircraft import AircraftCategory, AircraftClass
|
||||
from .db import user_collection
|
||||
from routes.utils import get_hashed_password
|
||||
from schemas.user import AuthLevel, UserCreateSchema
|
||||
@@ -13,6 +14,7 @@ logger = logging.getLogger("api")
|
||||
def user_helper(user) -> dict:
|
||||
"""
|
||||
Convert given db response into a format usable by UserDisplaySchema
|
||||
|
||||
:param user: Database response
|
||||
:return: Usable dict
|
||||
"""
|
||||
@@ -26,6 +28,7 @@ def user_helper(user) -> dict:
|
||||
def system_user_helper(user) -> dict:
|
||||
"""
|
||||
Convert given db response to a format usable by UserSystemSchema
|
||||
|
||||
:param user: Database response
|
||||
:return: Usable dict
|
||||
"""
|
||||
@@ -40,6 +43,7 @@ def system_user_helper(user) -> dict:
|
||||
def create_user_helper(user) -> dict:
|
||||
"""
|
||||
Convert given db response to a format usable by UserCreateSchema
|
||||
|
||||
:param user: Database response
|
||||
:return: Usable dict
|
||||
"""
|
||||
@@ -53,6 +57,7 @@ def create_user_helper(user) -> dict:
|
||||
def flight_display_helper(flight: dict) -> dict:
|
||||
"""
|
||||
Convert given db response to a format usable by FlightDisplaySchema
|
||||
|
||||
:param flight: Database response
|
||||
:return: Usable dict
|
||||
"""
|
||||
@@ -65,6 +70,7 @@ def flight_display_helper(flight: dict) -> dict:
|
||||
def flight_add_helper(flight: dict, user: str) -> dict:
|
||||
"""
|
||||
Convert given flight schema and user string to a format that can be inserted into the db
|
||||
|
||||
:param flight: Flight request body
|
||||
:param user: User that created flight
|
||||
:return: Combined dict that can be inserted into db
|
||||
@@ -73,6 +79,36 @@ def flight_add_helper(flight: dict, user: str) -> dict:
|
||||
return flight
|
||||
|
||||
|
||||
def aircraft_add_helper(aircraft: dict, user: str) -> dict:
|
||||
"""
|
||||
Convert given aircraft dict to a format that can be inserted into the db
|
||||
|
||||
:param aircraft: Aircraft request body
|
||||
:param user: User that created aircraft
|
||||
:return: Combined dict that can be inserted into db
|
||||
"""
|
||||
aircraft["user"] = ObjectId(user)
|
||||
aircraft["aircraft_category"] = aircraft["aircraft_category"].name
|
||||
aircraft["aircraft_class"] = aircraft["aircraft_class"].name
|
||||
return aircraft
|
||||
|
||||
|
||||
def aircraft_display_helper(aircraft: dict) -> dict:
|
||||
"""
|
||||
Convert given db response into a format usable by AircraftDisplaySchema
|
||||
|
||||
:param aircraft:
|
||||
:return: USable dict
|
||||
"""
|
||||
aircraft["id"] = str(aircraft["_id"])
|
||||
aircraft["user"] = str(aircraft["user"])
|
||||
if aircraft["aircraft_category"] is not AircraftCategory:
|
||||
aircraft["aircraft_category"] = AircraftCategory.__members__.get(aircraft["aircraft_category"])
|
||||
if aircraft["aircraft_class"] is not AircraftClass:
|
||||
aircraft["aircraft_class"] = AircraftClass.__members__.get(aircraft["aircraft_class"])
|
||||
return aircraft
|
||||
|
||||
|
||||
# UTILS #
|
||||
|
||||
async def create_admin_user():
|
||||
|
Reference in New Issue
Block a user