Skip to content

Suhas Unni Onboarding - Backend & Frontend#13

Closed
suhasunni wants to merge 15 commits intoUWOrbital:mainfrom
suhasunni:main
Closed

Suhas Unni Onboarding - Backend & Frontend#13
suhasunni wants to merge 15 commits intoUWOrbital:mainfrom
suhasunni:main

Conversation

@suhasunni
Copy link

@suhasunni suhasunni commented Feb 16, 2025

Purpose

Completed entire onboarding task.

New Changes

Testing

Passed 13/13 backend tests.

Outstanding Changes

Copy link
Contributor

@Yarik-Popov Yarik-Popov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall good start. Some changes are needed to the backend and existing frontend code to improve it

"""
# TODO:(Member) Implement this endpoint
query = select(Command).where(Command.id == id)
removedItem = db.exec(query).first()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our naming convention for the backend is the python naming convention so variables are in snake_case. So change it to removed_item


if removedItem is None:
raise HTTPException(status_code=404, detail="Item does not exist.")
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Comment on lines 32 to 40
try
{
const { data } = await axios.get<CommandListResponse>(`${API_URL}/commands/`);
return data;
} catch (error)
{
console.error(error);
throw error;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here is redundant as the delete endpoint returns the data. Just use the returned result of the delete call

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines 22 to 23
deleteCommand(id);
const data = await getCommands();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

@Yarik-Popov Yarik-Popov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')}.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@suhasunni suhasunni changed the title Suhas Unni Onboarding - Backend Suhas Unni Onboarding - Backend & Frontend Feb 19, 2025
Copy link
Contributor

@Yarik-Popov Yarik-Popov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did u get any cors issues when running the web client?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, this causes cors errors. Add your URL to the list and keep the original one

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did have some cors issues, changing the link fixed it for me, I'll add the original back to the list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where u accessing the frontend on localhost or via 127...?

Comment on lines 21 to 26
try {
const response = await deleteCommand(id);
setCommands(response.data);
} catch (error) {
console.error("Error deleting item: ", error);
throw error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function is at the component level, it shouldnt throw an exception but display a user message instead that there was an error

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is unused so remove it

setMainCommands(response);
} catch (error) {
console.error("Error fetching main commands: ", error);
throw error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldnt be throwing here but display some sort of message to the user that there was an error

Comment on lines 30 to 38
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unintentional and will be dealt with later on when we improve the gs onboarding

Copy link
Contributor

@Yarik-Popov Yarik-Popov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORS issues

"""
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, this causes cors errors. Add your URL to the list and keep the original one

Copy link
Contributor

@Yarik-Popov Yarik-Popov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be last set of changes

const fetchMainCommands = async() => {
try {
const response:MainCommandListResponse = await getMainCommands();
setMainCommands(response);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants