Fix FastAPI doc pages.

We can't directly use frozen dataclasses from pydcs in our interface
because pydantic can't process them. Pydantic is able to automatically
convert to our modelview type from the pydcs type though.
This commit is contained in:
Dan Albert
2022-02-25 16:34:11 -08:00
parent 45e76e12b6
commit d6e82d44fc
6 changed files with 25 additions and 16 deletions

View File

@@ -1,16 +1,15 @@
from __future__ import annotations
from dcs.mapping import LatLng
from pydantic.dataclasses import dataclass
from pydantic import BaseModel
from game.ato import FlightWaypoint
from game.ato.flightwaypointtype import FlightWaypointType
from game.server.leaflet import LeafletPoint
@dataclass
class FlightWaypointJs:
class FlightWaypointJs(BaseModel):
name: str
position: LatLng
position: LeafletPoint
altitude_ft: float
altitude_reference: str
is_movable: bool

View File

@@ -8,6 +8,7 @@ from game import Game
from game.ato.flightwaypoint import FlightWaypoint
from game.ato.flightwaypointtype import FlightWaypointType
from game.server import GameContext
from game.server.leaflet import LeafletPoint
from game.server.waypoints.models import FlightWaypointJs
from game.utils import meters
@@ -37,7 +38,7 @@ def all_waypoints_for_flight(
def set_position(
flight_id: UUID,
waypoint_idx: int,
position: LatLng,
position: LeafletPoint,
game: Game = Depends(GameContext.get),
) -> None:
flight = game.db.flights.get(flight_id)
@@ -45,7 +46,9 @@ def set_position(
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
waypoint = flight.flight_plan.waypoints[waypoint_idx - 1]
waypoint.position = Point.from_latlng(position, game.theater.terrain)
waypoint.position = Point.from_latlng(
LatLng(position.lat, position.lng), game.theater.terrain
)
package_model = (
GameContext.get_model()
.ato_model_for(flight.blue)