Skip to content

Commit dc40720

Browse files
addresses review comments
1 parent 77efcc2 commit dc40720

File tree

8 files changed

+37
-34
lines changed

8 files changed

+37
-34
lines changed

lib/controllers/environment.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ async def create_env(self) -> Union[EnvCreated, HTTPException]:
7070
views.EnvCreated
7171
"""
7272
try:
73-
with EnvRepository.fetch_env(self.env) as env_repo:
73+
with EnvRepository() as env_repo:
74+
env_repo.fetch_env(self.env)
7475
await env_repo.create_env()
7576
except Exception as e:
7677
exc_str = parse_error(e)
@@ -179,7 +180,8 @@ async def update_env_by_id(
179180
HTTP 404 Not Found: If the env is not found in the database.
180181
"""
181182
try:
182-
with EnvRepository.fetch_env(self.env) as env_repo:
183+
with EnvRepository() as env_repo:
184+
env_repo.fetch_env_by_id(env_id)
183185
await env_repo.create_env()
184186
await env_repo.delete_env_by_id(env_id)
185187
except Exception as e:

lib/controllers/flight.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ async def create_flight(self) -> Union[FlightCreated, HTTPException]:
107107
views.FlightCreated
108108
"""
109109
try:
110-
with FlightRepository.fetch_flight(self.flight) as flight_repo:
110+
with FlightRepository() as flight_repo:
111+
flight_repo.fetch_flight(self.flight)
111112
await flight_repo.create_flight(
112113
motor_kind=self.motor_kind,
113114
rocket_option=self.rocket_option,
@@ -219,7 +220,8 @@ async def update_flight_by_id(
219220
HTTP 404 Not Found: If the flight is not found in the database.
220221
"""
221222
try:
222-
with FlightRepository.fetch_flight(self.flight) as flight_repo:
223+
with FlightRepository() as flight_repo:
224+
flight_repo.fetch_flight(self.flight)
223225
await flight_repo.create_flight(
224226
motor_kind=self.motor_kind,
225227
rocket_option=self.rocket_option,
@@ -261,7 +263,8 @@ async def update_env_by_flight_id(
261263
new_flight = read_flight.dict()
262264
new_flight["environment"] = env
263265
new_flight = Flight(**new_flight)
264-
with FlightRepository.fetch_flight(new_flight) as flight_repo:
266+
with FlightRepository() as flight_repo:
267+
flight_repo.fetch_flight(new_flight)
265268
await flight_repo.create_flight(
266269
motor_kind=read_flight.rocket.motor.motor_kind,
267270
rocket_option=read_flight.rocket.rocket_option,
@@ -308,7 +311,8 @@ async def update_rocket_by_flight_id(
308311
new_flight = read_flight.dict()
309312
new_flight["rocket"] = updated_rocket
310313
new_flight = Flight(**new_flight)
311-
with FlightRepository.fetch_flight(new_flight) as flight_repo:
314+
with FlightRepository() as flight_repo:
315+
flight_repo.fetch_flight(new_flight)
312316
await flight_repo.create_flight(
313317
motor_kind=motor_kind, rocket_option=rocket_option
314318
)

lib/controllers/motor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ async def create_motor(self) -> Union[MotorCreated, HTTPException]:
118118
views.MotorCreated
119119
"""
120120
try:
121-
with MotorRepository.fetch_motor(self.motor) as motor_repo:
121+
with MotorRepository() as motor_repo:
122+
motor_repo.fetch_motor(self.motor)
122123
await motor_repo.create_motor(motor_kind=self.motor_kind)
123124
except Exception as e:
124125
exc_str = parse_error(e)
@@ -227,7 +228,8 @@ async def update_motor_by_id(
227228
HTTP 404 Not Found: If the motor is not found in the database.
228229
"""
229230
try:
230-
with MotorRepository.fetch_motor(self.motor) as motor_repo:
231+
with MotorRepository() as motor_repo:
232+
motor_repo.fetch_motor(self.motor)
231233
await motor_repo.create_motor(motor_kind=self.motor_kind)
232234
await motor_repo.delete_motor_by_id(motor_id)
233235
except Exception as e:

lib/controllers/rocket.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ async def create_rocket(self) -> Union[RocketCreated, HTTPException]:
155155
views.RocketCreated
156156
"""
157157
try:
158-
with RocketRepository.fetch_rocket(self.rocket) as rocket_repo:
158+
with RocketRepository() as rocket_repo:
159+
rocket_repo.fetch_rocket(self.rocket)
159160
await rocket_repo.create_rocket(
160161
rocket_option=self.rocket_option,
161162
motor_kind=self.motor_kind,
@@ -268,7 +269,8 @@ async def update_rocket_by_id(
268269
HTTP 404 Not Found: If the rocket is not found in the database.
269270
"""
270271
try:
271-
with RocketRepository.fetch_rocket(self.rocket) as rocket_repo:
272+
with RocketRepository() as rocket_repo:
273+
rocket_repo.fetch_rocket(self.rocket)
272274
await rocket_repo.create_rocket(
273275
rocket_option=self.rocket_option,
274276
motor_kind=self.motor_kind,

lib/repositories/environment.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ def __init__(self):
2020
super().__init__("environments")
2121
self._env = None
2222

23-
@classmethod
24-
def fetch_env(cls, environment: Env):
25-
instance = cls()
26-
instance.env = environment
27-
instance.env_id = environment.env_id
28-
return instance
23+
def fetch_env(self, environment: Env):
24+
self.env = environment
25+
self.env_id = environment.env_id
26+
return self
2927

3028
@property
3129
def env(self) -> Env:

lib/repositories/flight.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ def __init__(self):
2020
super().__init__("flights")
2121
self._flight = None
2222

23-
@classmethod
24-
def fetch_flight(cls, flight: Flight):
25-
instance = cls()
26-
instance.flight = flight
27-
instance.flight_id = flight.flight_id
28-
return instance
23+
def fetch_flight(self, flight: Flight):
24+
self.flight = flight
25+
self.flight_id = flight.flight_id
26+
return self
2927

3028
@property
3129
def flight(self) -> Flight:

lib/repositories/motor.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ def __init__(self):
2020
super().__init__("motors")
2121
self._motor = None
2222

23-
@classmethod
24-
def fetch_motor(cls, motor: Motor):
25-
instance = cls()
26-
instance.motor = motor
27-
instance.motor_id = motor.motor_id
28-
return instance
23+
def fetch_motor(self, motor: Motor):
24+
self.motor = motor
25+
self.motor_id = motor.motor_id
26+
return self
2927

3028
@property
3129
def motor(self) -> Motor:

lib/repositories/rocket.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ class RocketRepository(Repository):
1818

1919
def __init__(self):
2020
super().__init__("rockets")
21+
self._rocket = None
2122

22-
@classmethod
23-
def fetch_rocket(cls, rocket: Rocket):
24-
instance = cls()
25-
instance.rocket = rocket
26-
instance.rocket_id = rocket.rocket_id
27-
return instance
23+
def fetch_rocket(self, rocket: Rocket):
24+
self.rocket = rocket
25+
self.rocket_id = rocket.rocket_id
26+
return self
2827

2928
@property
3029
def rocket(self) -> Rocket:

0 commit comments

Comments
 (0)