@@ -26,18 +26,6 @@ class MotorController:
2626 - Create a rocketpy.Motor object from a Motor model object.
2727 """
2828
29- def __init__ (self , motor : Motor ):
30- self .guard (motor )
31- self ._motor = motor
32-
33- @property
34- def motor (self ) -> Motor :
35- return self ._motor
36-
37- @motor .setter
38- def motor (self , motor : Motor ):
39- self ._motor = motor
40-
4129 @staticmethod
4230 def guard (motor : Motor ):
4331 if (
@@ -51,15 +39,19 @@ def guard(motor: Motor):
5139
5240 # TODO: extend guard to check motor kinds and tank kinds specifics
5341
54- async def create_motor (self ) -> Union [MotorCreated , HTTPException ]:
42+ @classmethod
43+ async def create_motor (
44+ cls , motor : Motor
45+ ) -> Union [MotorCreated , HTTPException ]:
5546 """
5647 Create a models.Motor in the database.
5748
5849 Returns:
5950 views.MotorCreated
6051 """
6152 try :
62- async with MotorRepository (self .motor ) as motor_repo :
53+ cls .guard (motor )
54+ async with MotorRepository (motor ) as motor_repo :
6355 await motor_repo .create_motor ()
6456 except PyMongoError as e :
6557 logger .error (f"controllers.motor.create_motor: PyMongoError { e } " )
@@ -173,8 +165,9 @@ async def get_rocketpy_motor_binary(
173165 f"Call to controllers.motor.get_rocketpy_motor_binary completed for Motor { motor_id } "
174166 )
175167
168+ @classmethod
176169 async def update_motor_by_id (
177- self , motor_id : str
170+ cls , motor_id : str , motor : Motor
178171 ) -> Union [MotorUpdated , HTTPException ]:
179172 """
180173 Update a motor in the database.
@@ -189,7 +182,8 @@ async def update_motor_by_id(
189182 HTTP 404 Not Found: If the motor is not found in the database.
190183 """
191184 try :
192- async with MotorRepository (self .motor ) as motor_repo :
185+ cls .guard (motor )
186+ async with MotorRepository (motor ) as motor_repo :
193187 await motor_repo .update_motor_by_id (motor_id )
194188 except PyMongoError as e :
195189 logger .error (f"controllers.motor.update_motor: PyMongoError { e } " )
0 commit comments