@@ -25,9 +25,6 @@ class FlightController:
2525 """
2626 Controller for the Flight model.
2727
28- Init Attributes:
29- flight (models.Flight): Flight model object.
30-
3128 Enables:
3229 - Create a RocketPyFlight object from a Flight model object.
3330 - Generate trajectory simulation from a RocketPyFlight object.
@@ -39,34 +36,23 @@ class FlightController:
3936
4037 """
4138
42- def __init__ (
43- self ,
44- flight : Flight ,
45- ):
46- self .guard (flight )
47- self ._flight = flight
48-
49- @property
50- def flight (self ) -> Flight :
51- return self ._flight
52-
53- @flight .setter
54- def flight (self , flight : Flight ):
55- self ._flight = flight
56-
5739 @staticmethod
5840 def guard (flight : Flight ):
5941 RocketController .guard (flight .rocket )
6042
61- async def create_flight (self ) -> Union [FlightCreated , HTTPException ]:
43+ @classmethod
44+ async def create_flight (
45+ cls , flight : Flight
46+ ) -> Union [FlightCreated , HTTPException ]:
6247 """
6348 Create a flight in the database.
6449
6550 Returns:
6651 views.FlightCreated
6752 """
6853 try :
69- async with FlightRepository (self .flight ) as flight_repo :
54+ cls .guard (flight )
55+ async with FlightRepository (flight ) as flight_repo :
7056 await flight_repo .create_flight ()
7157 except PyMongoError as e :
7258 logger .error (f"controllers.flight.create_flight: PyMongoError { e } " )
@@ -189,8 +175,9 @@ async def get_rocketpy_flight_binary(
189175 f"Call to controllers.flight.get_rocketpy_flight_binary completed for Flight { flight_id } "
190176 )
191177
178+ @classmethod
192179 async def update_flight_by_id (
193- self , flight_id : str
180+ cls , flight : Flight , flight_id : str
194181 ) -> Union [FlightUpdated , HTTPException ]:
195182 """
196183 Update a models.Flight in the database.
@@ -205,7 +192,8 @@ async def update_flight_by_id(
205192 HTTP 404 Not Found: If the flight is not found in the database.
206193 """
207194 try :
208- async with FlightRepository (self .flight ) as flight_repo :
195+ cls .guard (flight )
196+ async with FlightRepository (flight ) as flight_repo :
209197 await flight_repo .update_flight_by_id (flight_id )
210198 except PyMongoError as e :
211199 logger .error (f"controllers.flight.update_flight: PyMongoError { e } " )
0 commit comments