Skip to content

Commit d09d9c9

Browse files
authored
Make Improvements to Onboarding 1 (UWOrbital#23)
# Purpose Closes UWOrbital#15. Inspired by UWOrbital#4 for the frontend improvements. # New Changes - Improve PR template - Improve datetime check test in `test_api.py` - Fix mismatch in `CommandRequest` on backend and frontend - Refactor frontend to no longer need to reload the page to display commands after delete or creation - Improve error messages in frontend API calls - Make frontend easier by removing some repetitive steps - Make `createCommand` endpoint signature consistent with backend `create_command` signature - Update Python doc strings to match the main repo's style guide # Testing Implemented the GS onboarding frontend and backend on a private branch, and the frontend worked properly. # Outstanding Changes None
1 parent c47b51d commit d09d9c9

File tree

17 files changed

+128
-75
lines changed

17 files changed

+128
-75
lines changed

.github/pull_request_template.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Purpose
22
Completed the GS on-boarding task. Include a screenshot of the front-end of the application.
33

4+
- [ ] I have added my name to the onboarding title (required)
5+
- [ ] I have added a screenshot of the logs printed by the logger middleware (required)
6+
- [ ] I am interested to work on the frontend (optional)
7+
48
# New Changes
59
- Explain new changes
610

711
# Testing
812
- Explain tests that you ran to verify code functionality.
9-
- Any functions that can be unit-tested should include a unit test in the PR. Otherwise, explain why it cannot be unit-tested.
10-
11-
# Outstanding Changes
12-
- If there are non-critical changes (i.e. additional features) that can be made to this feature in the future, indicate them here.

README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ All function and method parameters (except for the `self` and `cls` parameters)
1313
```python
1414
def my_add(num1: int, num2: int) -> int:
1515
"""
16-
@brief Adds two numbers together
16+
Adds two numbers together
1717
18-
@param num1 - The first number to add.
19-
@param num2 - The second number to add.
20-
@return Returns the sum of the two numbers.
18+
:param num1: The first number to add.
19+
:param num2: The second number to add.
20+
:return: Returns the sum of the two numbers.
2121
"""
2222
return num1 + num2
2323
```
@@ -72,21 +72,21 @@ Function and method comments using `""" """` should exist below the function dec
7272
```python
7373
def my_add(num1: int, num2: int) -> int:
7474
"""
75-
@brief Adds two numbers together
75+
Adds two numbers together
7676
77-
@param num1 - The first number to add.
78-
@param num2 - The second number to add.
79-
@return Returns the sum of the two numbers.
77+
:param num1: The first number to add.
78+
:param num2: The second number to add.
79+
:return: Returns the sum of the two numbers.
8080
"""
8181
return num1 + num2
8282
```
8383

8484
```python
8585
def increase_x(self, count: int) -> None:
8686
"""
87-
@brief Increases the x attribute by the count.
87+
Increases the x attribute by the count.
8888
89-
@param count - Count to increase the x attribute by.
89+
:param count: Count to increase the x attribute by.
9090
"""
9191
self.x += count
9292
```
@@ -105,9 +105,11 @@ File comments are not required
105105
```python
106106
class PointTwoDimension:
107107
"""
108-
@brief Class for storing a 2D point
109-
@attribute x (int) - x coordinate of the point
110-
@attribute y (int) - y coordinate of the point
108+
Class for storing a 2D point
109+
:param x: x coordinate of the point
110+
:type x: int
111+
:param y: y coordinate of the point
112+
:type y: int
111113
"""
112114

113115
def __init__(x: int, y: int):
@@ -117,9 +119,11 @@ class PointTwoDimension:
117119
@dataclasses.dataclass
118120
class PointTwoDimension:
119121
"""
120-
@brief Class for storing a 2D point
121-
@attribute x (int) - x coordinate of the point
122-
@attribute y (int) - y coordinate of the point
122+
Class for storing a 2D point
123+
:param x: x coordinate of the point
124+
:type x: int
125+
:param y: y coordinate of the point
126+
:type y: int
123127
"""
124128

125129
x: int

backend/api/endpoints/command.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from fastapi import APIRouter, Depends
2-
from fastapi.exceptions import HTTPException
32
from sqlmodel import Session, select
43

54
from backend.api.models.request_model import CommandRequest
@@ -16,7 +15,7 @@ def get_commands(db: Session = Depends(get_db)):
1615
"""
1716
Gets all the items
1817
19-
@return Returns a list of commands
18+
:return: Returns a list of commands
2019
"""
2120
query = select(Command)
2221
items = db.exec(query).all()
@@ -28,8 +27,8 @@ def create_command(payload: CommandRequest):
2827
"""
2928
Creates an item with the given payload in the database and returns this payload after pulling it from the database
3029
31-
@param payload: The data used to create an item
32-
@return returns a json object with field of "data" under which there is the payload now pulled from the database
30+
:param payload: The data used to create an item
31+
:return: returns a json object with field of "data" under which there is the payload now pulled from the database
3332
"""
3433
# TODO:(Member) Implement this endpoint
3534

@@ -40,7 +39,7 @@ def delete_command(id: int):
4039
"""
4140
Deletes the item with the given id if it exists. Otherwise raises a 404 error.
4241
43-
@param id: The id of the item to delete
44-
@return returns the list of commands after deleting the item
42+
:param id: The id of the item to delete
43+
:return: returns the list of commands after deleting the item
4544
"""
4645
# TODO:(Member) Implement this endpoint

backend/api/endpoints/main_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def get_main_commands(db: Session = Depends(get_db)):
1414
"""
1515
Gets all the main commands that can be created.
1616
17-
@return Returns a list of main commands
17+
:return: Returns a list of main commands
1818
"""
1919
query = select(MainCommand)
2020
items = db.exec(query).all()

backend/api/middlewares/cors_middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def add_cors_middleware(app: FastAPI) -> None:
66
"""
77
Adds the cors middleware to the FastAPI app
88
9-
@param app: FastAPI app to add the middleware to
9+
:param app: FastAPI app to add the middleware to
1010
"""
1111
app.add_middleware(
1212
CORSMiddleware,

backend/api/middlewares/logger_middleware.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ async def dispatch(
1313
datetime of request, duration of execution. Logs should be printed using the custom logging module provided.
1414
Logs should be printed so that they are easily readable and understandable.
1515
16-
@param request: Request received to this middleware from client (it is supplied by FastAPI)
17-
@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)
18-
@return Response from endpoint
16+
:param request: Request received to this middleware from client (it is supplied by FastAPI)
17+
: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)
18+
:return: Response from endpoint
1919
"""
2020
# TODO:(Member) Finish implementing this method
2121
response = await call_next(request)

backend/data/base_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
class BaseSQLModel(SQLModel):
66
"""
7-
Base SQL Model class. It performs validation on the model unlike the default SQLModel class with table=True.
7+
Base SQL Model class.
8+
It performs validation on the model unlike the default SQLModel class with table=True.
89
"""
910

1011
def __init__(self, **data):

backend/data/enums.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class CommandStatus(Enum):
66
"""
77
Enum representing the command status.
88
9-
@warning This enum shouldn't be modified
9+
:warning: This enum shouldn't be modified
1010
"""
1111

1212
PENDING = auto()

backend/utils/logging.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414

1515
def logger_setup(*, enqueue: bool = False, diagnose: bool = True) -> None:
1616
"""
17-
Set up the global logger
17+
Set up the global logger. It modifies the global logger object.
1818
The logger will log everything to a file, info to stdout, and warnings and above to stderr.
19-
@param enqueue - Whether to enqueue messages for asynchronous processing.
20-
@param diagnose - Whether to enable diagnostic mode.
21-
@return None - Modifies the global logger object
19+
:param enqueue: Whether to enqueue messages for asynchronous processing.
20+
:param diagnose: Whether to enable diagnostic mode.
2221
"""
2322
# Remove any existing sinks
2423
logger.remove()

frontend/src/app.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1+
import { useEffect, useState } from 'react'
12
import './app.css'
23
import CommandTable from './display/table'
34
import CommandInput from './input/command_input'
5+
import { CommandResponse } from './data/response'
6+
import { getCommands } from './display/command_api'
47

58
function App() {
9+
const [commands, setCommands] = useState<CommandResponse[]>([])
10+
11+
useEffect(() => {
12+
const getCommandsFn = async () => {
13+
try {
14+
const data = await getCommands();
15+
setCommands(data.data)
16+
} catch (error) {
17+
console.error(error)
18+
alert("Error fetching commands")
19+
}
20+
}
21+
22+
getCommandsFn();
23+
}, [])
24+
625
return (
726
<>
8-
<CommandInput />
27+
<CommandInput setCommands={setCommands} />
928
<p>Command List:</p>
10-
<CommandTable />
29+
<CommandTable commands={commands} setCommands={setCommands} />
1130
</>
1231
)
1332
}

0 commit comments

Comments
 (0)