Skip to content

Commit 4c99de6

Browse files
refactors API architecture
- wipe business logic from controllers - turn off entities deletion - replace hash ids by ObjectIds disables simulation routes exposes motor tank property and disable fronzen instances
1 parent 3eed2f6 commit 4c99de6

30 files changed

+872
-5505
lines changed

README.md

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ touch .env && echo MONGODB_CONNECTION_STRING="$ConnectionString" > .env
1818
### Docker
1919
- run docker compose: `docker-compose up --build -d`
2020

21-
### Standard
21+
### Standalone
2222
- Dev: `python3 -m uvicorn lib:app --reload --port 3000`
2323
- Prod: `gunicorn -k uvicorn.workers.UvicornWorker lib:app -b 0.0.0.0:3000`
2424

@@ -38,6 +38,12 @@ $ touch .env && echo MONGODB_CONNECTION_STRING="$ConnectionString" > .env
3838
│   │   ├── motor.py
3939
│   │   └── rocket.py
4040
│   │  
41+
│   ├── services
42+
│   │   ├── environment.py
43+
│   │   ├── flight.py
44+
│   │   ├── motor.py
45+
│   │   └── rocket.py
46+
│   │  
4147
│   ├── routes
4248
│   │   ├── environment.py
4349
│   │   ├── flight.py
@@ -66,43 +72,51 @@ $ touch .env && echo MONGODB_CONNECTION_STRING="$ConnectionString" > .env
6672
│   └── rocket.py
6773
│  
6874
└── tests
69-
├── infinity-api-postman-collection.json
70-
│  
7175
├── integration
76+
│   ├── test_environment_integration.py
77+
│   ├── test_motor_integration.py
78+
│   ├── test_rocket_integration.py
79+
│   └── test_flight_integration.py
7280
│  
7381
└── unit
7482
├── test_secrets.py
7583
├── test_api.py
7684
│  
7785
├── test_controllers
78-
│   ├── test_environment.py
79-
│   ├── test_flight.py
80-
│   ├── test_motor.py
81-
│   └── test_rocket.py
86+
│   ├── test_environment_controller.py
87+
│   ├── test_flight_controller.py
88+
│   ├── test_motor_controller.py
89+
│   └── test_rocket_controller.py
90+
│  
91+
├── test_services
92+
│   ├── test_environment_service.py
93+
│   ├── test_flight_service.py
94+
│   ├── test_motor_service.py
95+
│   └── test_rocket_serice.py
8296
8397
├── test_routes
84-
│   ├── test_environment.py
85-
│   ├── test_flight.py
86-
│   ├── test_motor.py
87-
│   └── test_rocket.py
98+
│   ├── test_environment_route.py
99+
│   ├── test_flight_route.py
100+
│   ├── test_motor_route.py
101+
│   └── test_rocket_route.py
88102
89103
├── test_repositories
90-
│   ├── test_environment.py
91-
│   ├── test_flight.py
92-
│   ├── test_motor.py
93-
│   └── test_rocket.py
104+
│   ├── test_environment_repo.py
105+
│   ├── test_flight_repo.py
106+
│   ├── test_motor_repo.py
107+
│   └── test_rocket_repo.py
94108
95109
├── test_models
96-
│   ├── test_environment.py
97-
│   ├── test_flight.py
98-
│   ├── test_motor.py
99-
│   └── test_rocket.py
110+
│   ├── test_environment_model.py
111+
│   ├── test_flight_model.py
112+
│   ├── test_motor_model.py
113+
│   └── test_rocket_model.py
100114
│  
101115
└── test_views
102-
   ├── test_environment.py
103-
   ├── test_flight.py
104-
   ├── test_motor.py
105-
   └── test_rocket.py
116+
   ├── test_environment_view.py
117+
   ├── test_flight_view.py
118+
   ├── test_motor_view.py
119+
   └── test_rocket_view.py
106120
```
107121

108122
## DOCS

lib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
def parse_error(error):
2323
exc_type = type(error).__name__
2424
exc_obj = f"{error}".replace("\n", " ").replace(" ", " ")
25-
return f"{exc_type} exception: {exc_obj}"
25+
return f"{exc_type}: {exc_obj}"
2626

2727

2828
from lib.api import app

lib/controllers/environment.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ async def create_env(self) -> Union[EnvCreated, HTTPException]:
4848
views.EnvCreated
4949
"""
5050
try:
51-
async with EnvRepository() as env_repo:
52-
env_repo.fetch_env(self.env)
51+
async with EnvRepository(self.env) as env_repo:
5352
await env_repo.create_env()
5453
except PyMongoError as e:
5554
logger.error(
@@ -69,10 +68,10 @@ async def create_env(self) -> Union[EnvCreated, HTTPException]:
6968
detail=f"Failed to create environment: {exc_str}",
7069
) from e
7170
else:
72-
return EnvCreated(env_id=self.env.env_id)
71+
return EnvCreated(env_id=env_repo.env_id)
7372
finally:
7473
logger.info(
75-
f"Call to controllers.environment.create_env completed for Env {hash(self.env)}"
74+
f"Call to controllers.environment.create_env completed for Env {env_repo.env_id}"
7675
)
7776

7877
@staticmethod
@@ -178,10 +177,8 @@ async def update_env_by_id(
178177
HTTP 404 Not Found: If the env is not found in the database.
179178
"""
180179
try:
181-
async with EnvRepository() as env_repo:
182-
env_repo.fetch_env(self.env)
183-
await env_repo.create_env()
184-
await env_repo.delete_env_by_id(env_id)
180+
async with EnvRepository(self.env) as env_repo:
181+
await env_repo.update_env_by_id(env_id)
185182
except PyMongoError as e:
186183
logger.error(
187184
f"controllers.environment.update_env: PyMongoError {e}"
@@ -200,10 +197,10 @@ async def update_env_by_id(
200197
detail=f"Failed to update environment: {exc_str}",
201198
) from e
202199
else:
203-
return EnvUpdated(new_env_id=self.env.env_id)
200+
return EnvUpdated(env_id=env_id)
204201
finally:
205202
logger.info(
206-
f"Call to controllers.environment.update_env completed for Env {env_id}; Env {hash(self.env)}"
203+
f"Call to controllers.environment.update_env completed for Env {env_id}"
207204
)
208205

209206
@staticmethod
@@ -243,7 +240,7 @@ async def delete_env_by_id(
243240
detail=f"Failed to delete environment: {exc_str}",
244241
) from e
245242
else:
246-
return EnvDeleted(deleted_env_id=env_id)
243+
return EnvDeleted(env_id=env_id)
247244
finally:
248245
logger.info(
249246
f"Call to controllers.environment.delete_env completed for Env {env_id}"

0 commit comments

Comments
 (0)