@@ -69,9 +69,10 @@ async def create_env(self) -> "Union[EnvCreated, HTTPException]":
69
69
Returns:
70
70
views.EnvCreated
71
71
"""
72
- env_repo = EnvRepository (environment = self .env )
73
72
try :
74
- await env_repo .create_env ()
73
+ created_env = await EnvRepository (
74
+ environment = self .env
75
+ ).create_env ()
75
76
except Exception as e :
76
77
exc_str = parse_error (e )
77
78
logging .error (
@@ -82,7 +83,7 @@ async def create_env(self) -> "Union[EnvCreated, HTTPException]":
82
83
detail = f"Failed to create environment: { e } " ,
83
84
) from e
84
85
else :
85
- return EnvCreated (env_id = env_repo .env_id )
86
+ return EnvCreated (env_id = created_env .env_id )
86
87
finally :
87
88
logging .info (
88
89
f"[{ datetime .now ()} ] Call to controllers.environment.create_env completed; params: Env { hash (self .env )} "
@@ -102,9 +103,8 @@ async def get_env_by_id(env_id: int) -> "Union[Env, HTTPException]":
102
103
Raises:
103
104
HTTP 404 Not Found: If the env is not found in the database.
104
105
"""
105
- env_repo = EnvRepository (env_id = env_id )
106
106
try :
107
- read_env = await env_repo .get_env ()
107
+ read_env = await EnvRepository ( env_id = env_id ) .get_env ()
108
108
except Exception as e :
109
109
exc_str = parse_error (e )
110
110
logging .error (
@@ -143,9 +143,10 @@ async def get_rocketpy_env_as_jsonpickle(
143
143
Raises:
144
144
HTTP 404 Not Found: If the env is not found in the database.
145
145
"""
146
- env_repo = EnvRepository (env_id = env_id )
147
146
try :
148
- read_env = await env_repo .get_env ()
147
+ read_env = await cls .get_env_by_id (env_id )
148
+ except HTTPException as e :
149
+ raise e from e
149
150
except Exception as e :
150
151
exc_str = parse_error (e )
151
152
logging .error (
@@ -156,14 +157,9 @@ async def get_rocketpy_env_as_jsonpickle(
156
157
detail = f"Failed to read environment: { e } " ,
157
158
) from e
158
159
else :
159
- if read_env :
160
- rocketpy_env = cls .get_rocketpy_env (read_env )
161
- return EnvPickle (
162
- jsonpickle_rocketpy_env = jsonpickle .encode (rocketpy_env )
163
- )
164
- raise HTTPException (
165
- status_code = status .HTTP_404_NOT_FOUND ,
166
- detail = "Environment not found" ,
160
+ rocketpy_env = await cls .get_rocketpy_env (read_env )
161
+ return EnvPickle (
162
+ jsonpickle_rocketpy_env = jsonpickle .encode (rocketpy_env )
167
163
)
168
164
finally :
169
165
logging .info (
@@ -185,16 +181,13 @@ async def update_env(
185
181
Raises:
186
182
HTTP 404 Not Found: If the env is not found in the database.
187
183
"""
188
- env_repo = EnvRepository (environment = self .env , env_id = env_id )
189
184
try :
190
- read_env = await env_repo .get_env ()
191
- if read_env :
192
- await env_repo .update_env ()
193
- else :
194
- raise HTTPException (
195
- status_code = status .HTTP_404_NOT_FOUND ,
196
- detail = "Environment not found" ,
197
- )
185
+ await EnvController .get_env_by_id (env_id )
186
+ updated_env = await EnvRepository (
187
+ environment = self .env , env_id = env_id
188
+ ).update_env ()
189
+ except HTTPException as e :
190
+ raise e from e
198
191
except Exception as e :
199
192
exc_str = parse_error (e )
200
193
logging .error (
@@ -205,7 +198,7 @@ async def update_env(
205
198
detail = f"Failed to update environment: { e } " ,
206
199
) from e
207
200
else :
208
- return EnvUpdated (new_env_id = env_repo .env_id )
201
+ return EnvUpdated (new_env_id = updated_env .env_id )
209
202
finally :
210
203
logging .info (
211
204
f"[{ datetime .now ()} ] Call to controllers.environment.update_env completed; params: EnvID { env_id } , Env { hash (self .env )} "
@@ -225,9 +218,8 @@ async def delete_env(env_id: str) -> "Union[EnvDeleted, HTTPException]":
225
218
Raises:
226
219
HTTP 404 Not Found: If the env is not found in the database.
227
220
"""
228
- env_repo = EnvRepository (env_id = env_id )
229
221
try :
230
- await env_repo .delete_env ()
222
+ await EnvRepository ( env_id = env_id ) .delete_env ()
231
223
except Exception as e :
232
224
exc_str = parse_error (e )
233
225
logging .error (
@@ -258,9 +250,9 @@ async def simulate(cls, env_id: int) -> "Union[EnvSummary, HTTPException]":
258
250
Raises:
259
251
HTTP 404 Not Found: If the env does not exist in the database.
260
252
"""
261
- read_env = await cls .get_env_by_id (env_id )
262
253
try :
263
- rocketpy_env = cls .get_rocketpy_env (read_env )
254
+ read_env = await cls .get_env_by_id (env_id )
255
+ rocketpy_env = await cls .get_rocketpy_env (read_env )
264
256
env_simulation_numbers = EnvData .parse_obj (
265
257
rocketpy_env .all_info_returned ()
266
258
)
@@ -270,6 +262,8 @@ async def simulate(cls, env_id: int) -> "Union[EnvSummary, HTTPException]":
270
262
env_summary = EnvSummary (
271
263
env_data = env_simulation_numbers , env_plots = env_simulation_plots
272
264
)
265
+ except HTTPException as e :
266
+ raise e from e
273
267
except Exception as e :
274
268
exc_str = parse_error (e )
275
269
logging .error (
0 commit comments