Add endpoints to get categories and classese
This commit is contained in:
parent
f78be2cf86
commit
dafcacf28a
@ -4,7 +4,7 @@ from fastapi import APIRouter, Depends, HTTPException
|
||||
|
||||
from app.deps import get_current_user, admin_required
|
||||
from database import aircraft as db
|
||||
from schemas.aircraft import AircraftDisplaySchema, AircraftCreateSchema
|
||||
from schemas.aircraft import AircraftDisplaySchema, AircraftCreateSchema, category_class
|
||||
from schemas.user import UserDisplaySchema, AuthLevel
|
||||
|
||||
router = APIRouter()
|
||||
@ -36,6 +36,29 @@ async def get_all_aircraft() -> list[AircraftDisplaySchema]:
|
||||
return aircraft
|
||||
|
||||
|
||||
@router.get('/categories', summary="Get valid aircraft categories", status_code=200, response_model=dict)
|
||||
async def get_categories() -> dict:
|
||||
"""
|
||||
Get a list of valid aircraft categories
|
||||
|
||||
:return: List of categories
|
||||
"""
|
||||
return {"categories": list(category_class.keys())}
|
||||
|
||||
|
||||
@router.get('/class', summary="Get valid aircraft classes for the given class", status_code=200, response_model=dict)
|
||||
async def get_categories(category: str = "Airplane") -> dict:
|
||||
"""
|
||||
Get a list of valid aircraft classes for the given class
|
||||
|
||||
:return: List of classes
|
||||
"""
|
||||
if category not in category_class.keys():
|
||||
raise HTTPException(404, "Category not found")
|
||||
|
||||
return {"classes": category_class[category]}
|
||||
|
||||
|
||||
@router.get('/{aircraft_id}', summary="Get details of a given aircraft", response_model=AircraftDisplaySchema,
|
||||
status_code=200)
|
||||
async def get_aircraft_by_id(aircraft_id: str,
|
||||
|
@ -6,6 +6,37 @@ from pydantic_core.core_schema import ValidationInfo
|
||||
|
||||
from schemas.utils import PyObjectId, PositiveFloat
|
||||
|
||||
category_class = {
|
||||
"Airplane": [
|
||||
"Single-Engine Land",
|
||||
"Multi-Engine Land",
|
||||
"Single-Engine Sea",
|
||||
"Multi-Engine Sea",
|
||||
],
|
||||
"Rotorcraft": [
|
||||
"Helicopter",
|
||||
"Gyroplane",
|
||||
],
|
||||
"Powered Lift": [
|
||||
"Powered Lift",
|
||||
],
|
||||
"Glider": [
|
||||
"Glider",
|
||||
],
|
||||
"Lighter-Than-Air": [
|
||||
"Airship",
|
||||
"Balloon",
|
||||
],
|
||||
"Powered Parachute": [
|
||||
"Powered Parachute Land",
|
||||
"Powered Parachute Sea",
|
||||
],
|
||||
"Weight-Shift Control": [
|
||||
"Weight-Shift Control Land",
|
||||
"Weight-Shift Control Sea",
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
class AircraftCategory(Enum):
|
||||
airplane = "Airplane"
|
||||
|
Loading…
x
Reference in New Issue
Block a user