From 9baa18ac2df9a1ff49a568481cd6dd1852e4fb81 Mon Sep 17 00:00:00 2001 From: Gabriel Barberini Date: Sat, 5 Apr 2025 11:47:14 -0300 Subject: [PATCH 1/2] fixes flight summary retrieval --- src/controllers/environment.py | 12 ++++-------- src/controllers/flight.py | 12 ++++-------- src/controllers/motor.py | 8 ++++---- src/controllers/rocket.py | 12 ++++-------- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/controllers/environment.py b/src/controllers/environment.py index 3b5b075..15deb0a 100644 --- a/src/controllers/environment.py +++ b/src/controllers/environment.py @@ -36,10 +36,8 @@ async def get_rocketpy_environment_binary( Raises: HTTP 404 Not Found: If the env is not found in the database. """ - env_retrieved = await self.get_environment_by_id(env_id) - env_service = EnvironmentService.from_env_model( - env_retrieved.environment - ) + env = await self.get_environment_by_id(env_id) + env_service = EnvironmentService.from_env_model(env.environment) return env_service.get_environment_binary() @controller_exception_handler @@ -58,8 +56,6 @@ async def get_environment_simulation( Raises: HTTP 404 Not Found: If the env does not exist in the database. """ - env_retrieved = await self.get_environment_by_id(env_id) - env_service = EnvironmentService.from_env_model( - env_retrieved.environment - ) + env = await self.get_environment_by_id(env_id) + env_service = EnvironmentService.from_env_model(env.environment) return env_service.get_environment_simulation() diff --git a/src/controllers/flight.py b/src/controllers/flight.py index ac8624a..9b30398 100644 --- a/src/controllers/flight.py +++ b/src/controllers/flight.py @@ -82,10 +82,8 @@ async def get_rocketpy_flight_binary( Raises: HTTP 404 Not Found: If the flight is not found in the database. """ - flight_retrieved = await self.get_flight_by_id(flight_id) - flight_service = FlightService.from_flight_model( - flight_retrieved.flight - ) + flight = await self.get_flight_by_id(flight_id) + flight_service = FlightService.from_flight_model(flight.flight) return flight_service.get_flight_binary() @controller_exception_handler @@ -105,8 +103,6 @@ async def get_flight_simulation( Raises: HTTP 404 Not Found: If the flight does not exist in the database. """ - flight_retrieved = await self.get_flight_by_id(flight_id=flight_id) - flight_service = FlightService.from_flight_model( - flight_retrieved.flight - ) + flight = await self.get_flight_by_id(flight_id) + flight_service = FlightService.from_flight_model(flight.flight) return flight_service.get_flight_simulation() diff --git a/src/controllers/motor.py b/src/controllers/motor.py index e446cef..3483c1b 100644 --- a/src/controllers/motor.py +++ b/src/controllers/motor.py @@ -36,8 +36,8 @@ async def get_rocketpy_motor_binary( Raises: HTTP 404 Not Found: If the motor is not found in the database. """ - motor_retrieved = await self.get_motor_by_id(motor_id) - motor_service = MotorService.from_motor_model(motor_retrieved.motor) + motor = await self.get_motor_by_id(motor_id) + motor_service = MotorService.from_motor_model(motor.motor) return motor_service.get_motor_binary() @controller_exception_handler @@ -54,6 +54,6 @@ async def get_motor_simulation(self, motor_id: str) -> MotorSimulation: Raises: HTTP 404 Not Found: If the motor does not exist in the database. """ - motor_retrieved = await self.get_motor_by_id(motor_id) - motor_service = MotorService.from_motor_model(motor_retrieved.motor) + motor = await self.get_motor_by_id(motor_id) + motor_service = MotorService.from_motor_model(motor.motor) return motor_service.get_motor_simulation() diff --git a/src/controllers/rocket.py b/src/controllers/rocket.py index a7dcb4d..f586ccc 100644 --- a/src/controllers/rocket.py +++ b/src/controllers/rocket.py @@ -33,10 +33,8 @@ async def get_rocketpy_rocket_binary(self, rocket_id: str) -> bytes: Raises: HTTP 404 Not Found: If the rocket is not found in the database. """ - rocket_retrieved = await self.get_rocket_by_id(rocket_id) - rocket_service = RocketService.from_rocket_model( - rocket_retrieved.rocket - ) + rocket = await self.get_rocket_by_id(rocket_id) + rocket_service = RocketService.from_rocket_model(rocket.rocket) return rocket_service.get_rocket_binary() @controller_exception_handler @@ -56,8 +54,6 @@ async def get_rocket_simulation( Raises: HTTP 404 Not Found: If the rocket does not exist in the database. """ - rocket_retrieved = await self.get_rocket_by_id(rocket_id) - rocket_service = RocketService.from_rocket_model( - rocket_retrieved.rocket - ) + rocket = await self.get_rocket_by_id(rocket_id) + rocket_service = RocketService.from_rocket_model(rocket.rocket) return rocket_service.get_rocket_simulation() From 2393f443161fdf3e1faefba3981712a018751ec2 Mon Sep 17 00:00:00 2001 From: Gabriel Barberini Date: Sat, 5 Apr 2025 11:53:06 -0300 Subject: [PATCH 2/2] removes flight_id from additional rocketpy flight invocation parameters --- src/models/flight.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/models/flight.py b/src/models/flight.py index 44ac16a..93d36d4 100644 --- a/src/models/flight.py +++ b/src/models/flight.py @@ -34,6 +34,7 @@ def get_additional_parameters(self): if value is not None and key not in [ + "flight_id", "name", "environment", "rocket",