Skip to content

Commit 996c89b

Browse files
sanitizes controllers.flight dependencies
1 parent 984160c commit 996c89b

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

lib/controllers/flight.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,17 @@ def motor_kind(self) -> MotorKinds:
7777

7878
@flight.setter
7979
def flight(self, flight: Flight):
80-
self._flight= flight
80+
self._flight = flight
8181

8282
@staticmethod
83-
async def get_rocketpy_flight(flight: Flight, rocket_option: RocketOptions, motor_kind: MotorKinds) -> RocketPyFlight:
84-
rocketpy_rocket = RocketController.get_rocketpy_rocket(flight.rocket, rocket_option=rocket_option, motor_kind=motor_kind)
83+
async def get_rocketpy_flight(flight: Flight) -> RocketPyFlight:
84+
"""
85+
Get the rocketpy flight object.
86+
87+
Returns:
88+
RocketPyFlight
89+
"""
90+
rocketpy_rocket = RocketController.get_rocketpy_rocket(flight.rocket)
8591
rocketpy_env = EnvController.get_rocketpy_env(flight.environment)
8692
rocketpy_flight = RocketPyFlight(
8793
rocket=rocketpy_rocket,
@@ -92,7 +98,6 @@ async def get_rocketpy_flight(flight: Flight, rocket_option: RocketOptions, moto
9298
)
9399
return rocketpy_flight
94100

95-
96101
async def create_flight(self) -> "Union[FlightCreated, HTTPException]":
97102
"""
98103
Create a flight in the database.
@@ -121,12 +126,14 @@ async def create_flight(self) -> "Union[FlightCreated, HTTPException]":
121126
)
122127

123128
@staticmethod
124-
async def get_flight_by_id(flight_id: str) -> "Union[Flight, HTTPException]":
129+
async def get_flight_by_id(
130+
flight_id: str,
131+
) -> "Union[Flight, HTTPException]":
125132
"""
126133
Get a flight from the database.
127134
128135
Args:
129-
flight_id: str
136+
flight_id: str
130137
131138
Returns:
132139
models.Flight
@@ -166,7 +173,7 @@ async def get_rocketpy_flight_as_jsonpickle(
166173
Get rocketpy.flight as jsonpickle string.
167174
168175
Args:
169-
flight_id: str
176+
flight_id: str
170177
171178
Returns:
172179
views.FlightPickle
@@ -189,7 +196,7 @@ async def get_rocketpy_flight_as_jsonpickle(
189196
) from e
190197
else:
191198
rocketpy_flight = await cls.get_rocketpy_flight(
192-
read_flight, read_flight.rocket.rocket_option, read_flight.rocket.motor.motor_kind
199+
read_flight
193200
)
194201
return FlightPickle(
195202
jsonpickle_rocketpy_flight=jsonpickle.encode(rocketpy_flight)
@@ -206,7 +213,7 @@ async def update_flight(
206213
Update a flight in the database.
207214
208215
Args:
209-
flight_id: str
216+
flight_id: str
210217
211218
Returns:
212219
views.FlightUpdated
@@ -328,7 +335,7 @@ async def delete_flight(
328335
Delete a flight from the database.
329336
330337
Args:
331-
flight_id: str
338+
flight_id: str
332339
333340
Returns:
334341
views.FlightDeleted
@@ -337,9 +344,7 @@ async def delete_flight(
337344
HTTP 404 Not Found: If the flight is not found in the database.
338345
"""
339346
try:
340-
await FlightRepository(
341-
flight_id=flight_id
342-
).delete_flight()
347+
await FlightRepository(flight_id=flight_id).delete_flight()
343348
except HTTPException as e:
344349
raise e from e
345350
except Exception as e:
@@ -358,13 +363,14 @@ async def delete_flight(
358363

359364
@classmethod
360365
async def simulate_flight(
361-
cls, flight_id: str,
366+
cls,
367+
flight_id: str,
362368
) -> "Union[FlightSummary, HTTPException]":
363369
"""
364370
Simulate a rocket flight.
365371
366372
Args:
367-
flight_id: str
373+
flight_id: str
368374
369375
Returns:
370376
Flight summary view.
@@ -374,15 +380,7 @@ async def simulate_flight(
374380
"""
375381
try:
376382
read_flight = await cls.get_flight_by_id(flight_id=flight_id)
377-
rocketpy_flight = cls.get_rocketpy_flight(
378-
flight=read_flight,
379-
rocket_option=RocketOptions(
380-
read_flight.rocket.rocket_option
381-
),
382-
motor_kind=MotorKinds(
383-
read_flight.rocket.motor.motor_kind
384-
)
385-
)
383+
rocketpy_flight = cls.get_rocketpy_flight(flight=read_flight)
386384
flight = rocketpy_flight
387385

388386
_initial_conditions = InitialConditions(

0 commit comments

Comments
 (0)