Skip to content

Commit

Permalink
addresses review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBarberini committed May 24, 2024
1 parent 77efcc2 commit dc40720
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 34 deletions.
6 changes: 4 additions & 2 deletions lib/controllers/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ async def create_env(self) -> Union[EnvCreated, HTTPException]:
views.EnvCreated
"""
try:
with EnvRepository.fetch_env(self.env) as env_repo:
with EnvRepository() as env_repo:
env_repo.fetch_env(self.env)
await env_repo.create_env()
except Exception as e:
exc_str = parse_error(e)
Expand Down Expand Up @@ -179,7 +180,8 @@ async def update_env_by_id(
HTTP 404 Not Found: If the env is not found in the database.
"""
try:
with EnvRepository.fetch_env(self.env) as env_repo:
with EnvRepository() as env_repo:
env_repo.fetch_env_by_id(env_id)
await env_repo.create_env()
await env_repo.delete_env_by_id(env_id)
except Exception as e:
Expand Down
12 changes: 8 additions & 4 deletions lib/controllers/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ async def create_flight(self) -> Union[FlightCreated, HTTPException]:
views.FlightCreated
"""
try:
with FlightRepository.fetch_flight(self.flight) as flight_repo:
with FlightRepository() as flight_repo:
flight_repo.fetch_flight(self.flight)
await flight_repo.create_flight(
motor_kind=self.motor_kind,
rocket_option=self.rocket_option,
Expand Down Expand Up @@ -219,7 +220,8 @@ async def update_flight_by_id(
HTTP 404 Not Found: If the flight is not found in the database.
"""
try:
with FlightRepository.fetch_flight(self.flight) as flight_repo:
with FlightRepository() as flight_repo:
flight_repo.fetch_flight(self.flight)
await flight_repo.create_flight(
motor_kind=self.motor_kind,
rocket_option=self.rocket_option,
Expand Down Expand Up @@ -261,7 +263,8 @@ async def update_env_by_flight_id(
new_flight = read_flight.dict()
new_flight["environment"] = env
new_flight = Flight(**new_flight)
with FlightRepository.fetch_flight(new_flight) as flight_repo:
with FlightRepository() as flight_repo:
flight_repo.fetch_flight(new_flight)
await flight_repo.create_flight(
motor_kind=read_flight.rocket.motor.motor_kind,
rocket_option=read_flight.rocket.rocket_option,
Expand Down Expand Up @@ -308,7 +311,8 @@ async def update_rocket_by_flight_id(
new_flight = read_flight.dict()
new_flight["rocket"] = updated_rocket
new_flight = Flight(**new_flight)
with FlightRepository.fetch_flight(new_flight) as flight_repo:
with FlightRepository() as flight_repo:
flight_repo.fetch_flight(new_flight)
await flight_repo.create_flight(
motor_kind=motor_kind, rocket_option=rocket_option
)
Expand Down
6 changes: 4 additions & 2 deletions lib/controllers/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ async def create_motor(self) -> Union[MotorCreated, HTTPException]:
views.MotorCreated
"""
try:
with MotorRepository.fetch_motor(self.motor) as motor_repo:
with MotorRepository() as motor_repo:
motor_repo.fetch_motor(self.motor)
await motor_repo.create_motor(motor_kind=self.motor_kind)
except Exception as e:
exc_str = parse_error(e)
Expand Down Expand Up @@ -227,7 +228,8 @@ async def update_motor_by_id(
HTTP 404 Not Found: If the motor is not found in the database.
"""
try:
with MotorRepository.fetch_motor(self.motor) as motor_repo:
with MotorRepository() as motor_repo:
motor_repo.fetch_motor(self.motor)
await motor_repo.create_motor(motor_kind=self.motor_kind)
await motor_repo.delete_motor_by_id(motor_id)
except Exception as e:
Expand Down
6 changes: 4 additions & 2 deletions lib/controllers/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ async def create_rocket(self) -> Union[RocketCreated, HTTPException]:
views.RocketCreated
"""
try:
with RocketRepository.fetch_rocket(self.rocket) as rocket_repo:
with RocketRepository() as rocket_repo:
rocket_repo.fetch_rocket(self.rocket)
await rocket_repo.create_rocket(
rocket_option=self.rocket_option,
motor_kind=self.motor_kind,
Expand Down Expand Up @@ -268,7 +269,8 @@ async def update_rocket_by_id(
HTTP 404 Not Found: If the rocket is not found in the database.
"""
try:
with RocketRepository.fetch_rocket(self.rocket) as rocket_repo:
with RocketRepository() as rocket_repo:
rocket_repo.fetch_rocket(self.rocket)
await rocket_repo.create_rocket(
rocket_option=self.rocket_option,
motor_kind=self.motor_kind,
Expand Down
10 changes: 4 additions & 6 deletions lib/repositories/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ def __init__(self):
super().__init__("environments")
self._env = None

@classmethod
def fetch_env(cls, environment: Env):
instance = cls()
instance.env = environment
instance.env_id = environment.env_id
return instance
def fetch_env(self, environment: Env):
self.env = environment
self.env_id = environment.env_id
return self

@property
def env(self) -> Env:
Expand Down
10 changes: 4 additions & 6 deletions lib/repositories/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ def __init__(self):
super().__init__("flights")
self._flight = None

@classmethod
def fetch_flight(cls, flight: Flight):
instance = cls()
instance.flight = flight
instance.flight_id = flight.flight_id
return instance
def fetch_flight(self, flight: Flight):
self.flight = flight
self.flight_id = flight.flight_id
return self

@property
def flight(self) -> Flight:
Expand Down
10 changes: 4 additions & 6 deletions lib/repositories/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ def __init__(self):
super().__init__("motors")
self._motor = None

@classmethod
def fetch_motor(cls, motor: Motor):
instance = cls()
instance.motor = motor
instance.motor_id = motor.motor_id
return instance
def fetch_motor(self, motor: Motor):
self.motor = motor
self.motor_id = motor.motor_id
return self

@property
def motor(self) -> Motor:
Expand Down
11 changes: 5 additions & 6 deletions lib/repositories/rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ class RocketRepository(Repository):

def __init__(self):
super().__init__("rockets")
self._rocket = None

@classmethod
def fetch_rocket(cls, rocket: Rocket):
instance = cls()
instance.rocket = rocket
instance.rocket_id = rocket.rocket_id
return instance
def fetch_rocket(self, rocket: Rocket):
self.rocket = rocket
self.rocket_id = rocket.rocket_id
return self

@property
def rocket(self) -> Rocket:
Expand Down

0 comments on commit dc40720

Please sign in to comment.