Suhas Unni Onboarding - Backend & Frontend#13
Suhas Unni Onboarding - Backend & Frontend#13suhasunni wants to merge 15 commits intoUWOrbital:mainfrom suhasunni:main
Conversation
Yarik-Popov
left a comment
There was a problem hiding this comment.
Overall good start. Some changes are needed to the backend and existing frontend code to improve it
backend/api/endpoints/command.py
Outdated
| """ | ||
| # TODO:(Member) Implement this endpoint | ||
| query = select(Command).where(Command.id == id) | ||
| removedItem = db.exec(query).first() |
There was a problem hiding this comment.
Our naming convention for the backend is the python naming convention so variables are in snake_case. So change it to removed_item
backend/api/endpoints/command.py
Outdated
|
|
||
| if removedItem is None: | ||
| raise HTTPException(status_code=404, detail="Item does not exist.") | ||
| else: |
There was a problem hiding this comment.
No need for the else here as we will only execute the following code if there is no exception raised
| from fastapi import Request, Response | ||
| from starlette.middleware.base import BaseHTTPMiddleware | ||
| from datetime import datetime | ||
| import time |
There was a problem hiding this comment.
Based on your import convention, you should only be importing what you need ie dont import eh entire module if you only need time.time()
frontend/src/display/command_api.ts
Outdated
| try | ||
| { | ||
| const { data } = await axios.get<CommandListResponse>(`${API_URL}/commands/`); | ||
| return data; | ||
| } catch (error) | ||
| { | ||
| console.error(error); | ||
| throw error; | ||
| } |
There was a problem hiding this comment.
The code here is redundant as the delete endpoint returns the data. Just use the returned result of the delete call
There was a problem hiding this comment.
Normally we dont add formatting to the onboarding repos but it might be something that we add when we switch to using Deno 2 on this repo. You dont need to change anything based on this comment
frontend/src/display/table.tsx
Outdated
| deleteCommand(id); | ||
| const data = await getCommands(); |
There was a problem hiding this comment.
Since the deleteCommand already returns all the data after deleting it just use that.
There might be a race condition in the code where it will execute the getCommands() before the deleteCommand finishes thus getting the old data as there is no await on the deleteCommand statement
Yarik-Popov
left a comment
There was a problem hiding this comment.
I added a comment explaining why the pytest gh action is failing
| @return Response from endpoint | ||
| """ | ||
| # TODO:(Member) Finish implementing this method | ||
| logger.info(f'Date of request: {datetime.now().strftime('%A, %d. %B %Y %I: %M%p')}.') |
There was a problem hiding this comment.
Since the version of python used is 3.10, you cant have multiple ' in the same f string. This is a feature of 3.12
Yarik-Popov
left a comment
There was a problem hiding this comment.
Congrats on finishing the backend. You can dm me your email and ill add you to the notion if you want you can already start working on a backend task.
Thanks for including a video of the frontend working. Looks like the frontend has some build issues due to unused variables. Check the github action and remove them. Overall the frontend was done well. Some changes are needed to improve it
| """ | ||
| app.add_middleware( | ||
| CORSMiddleware, | ||
| allow_origins=["http://localhost:5173"], |
There was a problem hiding this comment.
Did u get any cors issues when running the web client?
There was a problem hiding this comment.
For me, this causes cors errors. Add your URL to the list and keep the original one
There was a problem hiding this comment.
I did have some cors issues, changing the link fixed it for me, I'll add the original back to the list.
There was a problem hiding this comment.
Where u accessing the frontend on localhost or via 127...?
frontend/src/display/table.tsx
Outdated
| try { | ||
| const response = await deleteCommand(id); | ||
| setCommands(response.data); | ||
| } catch (error) { | ||
| console.error("Error deleting item: ", error); | ||
| throw error; |
There was a problem hiding this comment.
Since this function is at the component level, it shouldnt throw an exception but display a user message instead that there was an error
frontend/src/input/command_input.tsx
Outdated
| const [mainCommands, setMainCommands] = useState<MainCommandListResponse|null>(null); | ||
| const [selectedMainCommand, setSelectedMainCommand] = useState<MainCommandResponse|null>(null); | ||
| const [ commandParams, setCommandParams ] = useState<{[key:string]: string}|null>(null); | ||
| const [ listTrigger, setListTrigger ] = useState(0); |
There was a problem hiding this comment.
This variable is unused so remove it
frontend/src/input/command_input.tsx
Outdated
| setMainCommands(response); | ||
| } catch (error) { | ||
| console.error("Error fetching main commands: ", error); | ||
| throw error; |
There was a problem hiding this comment.
You shouldnt be throwing here but display some sort of message to the user that there was an error
frontend/src/input/command_input.tsx
Outdated
| if (mainCommands){ | ||
| const response = mainCommands.data.find((command:MainCommandResponse) => (command.id.toString() === e.target.value)); | ||
| //response could be null if not found | ||
| if (response) { | ||
| setSelectedMainCommand(response); | ||
| const newParams: {[key:string]: string} = {}; | ||
| response.params?.split(',').forEach((param) => (newParams[param] = "")); | ||
| setCommandParams(newParams); | ||
| } |
There was a problem hiding this comment.
This is quite indented. U should use guard clauses. So invert the if statements and have an early return with a user error message
| name: selectedMainCommand.name, | ||
| params: Object.keys(commandParams).map((param) => commandParams[param]).join(","), | ||
| format: null, | ||
| // command_type IS part of CommandRequest in the backend but NOT the frontend model...is this intentional? |
There was a problem hiding this comment.
This is unintentional and will be dealt with later on when we improve the gs onboarding
| """ | ||
| app.add_middleware( | ||
| CORSMiddleware, | ||
| allow_origins=["http://localhost:5173"], |
There was a problem hiding this comment.
For me, this causes cors errors. Add your URL to the list and keep the original one
Yarik-Popov
left a comment
There was a problem hiding this comment.
Should be last set of changes
| const fetchMainCommands = async() => { | ||
| try { | ||
| const response:MainCommandListResponse = await getMainCommands(); | ||
| setMainCommands(response); |
There was a problem hiding this comment.
Set the selectedCommand here to be the response.data[0] id the response.data.length > 0. Also check that response isnt null before doing the length check
Purpose
Completed entire onboarding task.
New Changes
Testing
Passed 13/13 backend tests.
Outstanding Changes