-
Notifications
You must be signed in to change notification settings - Fork 73
Kai ZHang GS-Onboarding #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
9fdb485
7963006
052d395
0c4903c
2a9a8ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,10 @@ | |
| from typing import Any | ||
| from fastapi import Request, Response | ||
| from starlette.middleware.base import BaseHTTPMiddleware | ||
|
|
||
| from backend.utils.logging import logger_setup, logger_setup_file, logger_close | ||
| from loguru import logger | ||
| import time | ||
| import json | ||
|
|
||
| class LoggerMiddleware(BaseHTTPMiddleware): | ||
| async def dispatch( | ||
|
|
@@ -17,6 +20,21 @@ async def dispatch( | |
| :param call_next: Endpoint or next middleware to be called (if any, this is the next middleware in the chain of middlewares, it is supplied by FastAPI) | ||
| :return: Response from endpoint | ||
| """ | ||
| # TODO:(Member) Finish implementing this method | ||
|
|
||
| command_request_body = await request.body() | ||
| try: command_request_body = json.loads(command_request_body.decode("utf-8")) | ||
| except json.JSONDecodeError: command_request_body = {} | ||
| command_request_params = command_request_body.get("params") | ||
|
|
||
| start_time = time.perf_counter() | ||
| response = await call_next(request) | ||
| end_time = time.perf_counter() | ||
| execution_time = end_time - start_time | ||
|
|
||
| logger_setup() | ||
|
||
| logger_setup_file() | ||
|
|
||
| logger.info("Received a request with paramters: {} \n Duration of execution: {}", command_request_params, execution_time) | ||
| await logger_close() | ||
| return response | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,12 @@ def validate_params_format(self): | |
| In either of these cases return self. Otherwise raise a ValueError. | ||
| The format of the comma seperated values is "data1,data2" so no spaces between data and the commas. | ||
| """ | ||
| # TODO: (Member) Implement this method | ||
| num_values = 0 | ||
| if self.params != None: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try making these |
||
| if self.format == None: raise ValueError | ||
| if len(self.format.split(",")) != len(self.params.split(",")): raise ValueError | ||
| else: | ||
| if self.format != None: raise ValueError | ||
| return self | ||
|
|
||
|
|
||
|
|
@@ -41,7 +46,6 @@ class Command(BaseSQLModel, table=True): | |
| An instance of a MainCommand. | ||
| This table holds the data related to actual commands sent from the ground station up to the OBC. | ||
| """ | ||
|
|
||
| id: int | None = Field( | ||
| default=None, primary_key=True | ||
| ) # NOTE: Must be None for autoincrement | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like repeated functionality, you can use the
get_commands()function here!