Skip to content

Commit 55a445a

Browse files
removes unnecessary class init state info from controllers
1 parent 921153e commit 55a445a

File tree

6 files changed

+24
-54
lines changed

6 files changed

+24
-54
lines changed

lib/controllers/environment.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ class EnvController:
1919
"""
2020
Controller for the Environment model.
2121
22-
Init Attributes:
23-
env: models.Env
24-
2522
Enables:
2623
- Simulation of a RocketPy Environment from models.Env
2724
- CRUD operations over models.Env on the database

lib/controllers/flight.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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}")

lib/controllers/motor.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ class MotorController:
1919
"""
2020
Controller for the motor model.
2121
22-
Init Attributes:
23-
motor (models.Motor): Motor model object.
24-
2522
Enables:
2623
- Create a rocketpy.Motor object from a Motor model object.
2724
"""

lib/controllers/rocket.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,27 @@ class RocketController:
2222
"""
2323
Controller for the Rocket model.
2424
25-
Init Attributes:
26-
rocket: models.Rocket.
27-
2825
Enables:
2926
- CRUD operations over models.Rocket on the database.
3027
"""
3128

32-
def __init__(
33-
self,
34-
rocket: Rocket,
35-
):
36-
self.guard(rocket)
37-
self._rocket = rocket
38-
39-
@property
40-
def rocket(self) -> Rocket:
41-
return self._rocket
42-
43-
@rocket.setter
44-
def rocket(self, rocket: Rocket):
45-
self._rocket = rocket
46-
4729
@staticmethod
4830
def guard(rocket: Rocket):
4931
MotorController.guard(rocket.motor)
5032

51-
async def create_rocket(self) -> Union[RocketCreated, HTTPException]:
33+
@classmethod
34+
async def create_rocket(
35+
cls, rocket: Rocket
36+
) -> Union[RocketCreated, HTTPException]:
5237
"""
5338
Create a models.Rocket in the database.
5439
5540
Returns:
5641
views.RocketCreated
5742
"""
5843
try:
59-
async with RocketRepository(self.rocket) as rocket_repo:
44+
cls.guard(rocket)
45+
async with RocketRepository(rocket) as rocket_repo:
6046
await rocket_repo.create_rocket()
6147
except PyMongoError as e:
6248
logger.error(f"controllers.rocket.create_rocket: PyMongoError {e}")
@@ -175,8 +161,9 @@ async def get_rocketpy_rocket_binary(
175161
f"Call to controllers.rocket.get_rocketpy_rocket_binary completed for Rocket {rocket_id}"
176162
)
177163

164+
@classmethod
178165
async def update_rocket_by_id(
179-
self, rocket_id: str
166+
cls, rocket: Rocket, rocket_id: str
180167
) -> Union[RocketUpdated, HTTPException]:
181168
"""
182169
Update a models.Rocket in the database.
@@ -191,7 +178,8 @@ async def update_rocket_by_id(
191178
HTTP 404 Not Found: If the rocket is not found in the database.
192179
"""
193180
try:
194-
async with RocketRepository(self.rocket) as rocket_repo:
181+
cls.guard(rocket)
182+
async with RocketRepository(rocket) as rocket_repo:
195183
await rocket_repo.update_rocket_by_id(rocket_id)
196184
except PyMongoError as e:
197185
logger.error(f"controllers.rocket.update_rocket: PyMongoError {e}")

lib/routes/flight.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def create_flight(
4343
"""
4444
with tracer.start_as_current_span("create_flight"):
4545
flight.rocket.motor.set_motor_kind(motor_kind)
46-
return await FlightController(flight).create_flight()
46+
return await FlightController.create_flight(flight)
4747

4848

4949
@router.get("/{flight_id}")
@@ -146,7 +146,7 @@ async def update_flight(
146146
"""
147147
with tracer.start_as_current_span("update_flight"):
148148
flight.rocket.motor.set_motor_kind(motor_kind)
149-
return await FlightController(flight).update_flight_by_id(flight_id)
149+
return await FlightController.update_flight_by_id(flight, flight_id)
150150

151151

152152
@router.get("/{flight_id}/summary")

lib/routes/rocket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def create_rocket(
4141
"""
4242
with tracer.start_as_current_span("create_rocket"):
4343
rocket.motor.set_motor_kind(motor_kind)
44-
return await RocketController(rocket).create_rocket()
44+
return await RocketController.create_rocket(rocket)
4545

4646

4747
@router.get("/{rocket_id}")
@@ -73,7 +73,7 @@ async def update_rocket(
7373
"""
7474
with tracer.start_as_current_span("update_rocket"):
7575
rocket.motor.set_motor_kind(motor_kind)
76-
return await RocketController(rocket).update_rocket_by_id(rocket_id)
76+
return await RocketController.update_rocket_by_id(rocket, rocket_id)
7777

7878

7979
@router.get(

0 commit comments

Comments
 (0)