-
Notifications
You must be signed in to change notification settings - Fork 73
Gabriel Guirguis - GS Onboarding #21
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
Changes from 2 commits
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,6 +2,8 @@ | |
| from typing import Any | ||
| from fastapi import Request, Response | ||
| from starlette.middleware.base import BaseHTTPMiddleware | ||
| from loguru import logger | ||
| from time import perf_counter | ||
|
|
||
|
|
||
| class LoggerMiddleware(BaseHTTPMiddleware): | ||
|
|
@@ -17,6 +19,10 @@ 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 | ||
| start = perf_counter() | ||
|
|
||
| response = await call_next(request) | ||
|
|
||
| duration = perf_counter() - start | ||
| logger.info | ||
|
||
| return response | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,20 @@ 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 | ||
| validated_params = self.params | ||
| validated_format = self.format | ||
|
||
|
|
||
| if validated_params == None and validated_format == None: | ||
|
||
| return self | ||
| elif isinstance(validated_params, str) and (isinstance(validated_format, str)) and validated_params.count(",") == validated_format.count(","): | ||
|
||
| return self | ||
| else: | ||
| raise(ValueError | ||
| (f"""params and format must both be either None or have the same number of comma seperated values, | ||
| recieved: | ||
| params: {validated_params} | ||
| format: {validated_format}\n""")) | ||
|
||
|
|
||
| return self | ||
|
||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| export interface CommandRequest { | ||
| name: string | ||
| command_type: string | ||
| params: string | null | ||
| format: string | null | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,13 @@ export const getCommands = async (): Promise<CommandListResponse> => { | |
| * @param id: command to delete | ||
| * @returns Promise<CommandListResponse>: list of commands after the command with the given id was deleted | ||
| */ | ||
| export const deleteCommand = async (id: number): Promise<CommandListResponse> => { | ||
| try { | ||
| await axios.delete(`${API_URL}/${id}`) | ||
| const { data } = await axios.get<CommandListResponse>(`${API_URL}/commands/`) | ||
|
||
| return data; | ||
| } catch (error) { | ||
| console.error(error) | ||
| throw error | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,63 @@ | ||
| import "./command_input.css" | ||
| import { useEffect, useState } from "react"; | ||
| import { MainCommandResponse } from "../data/response"; | ||
| import "./command_input.css"; | ||
| import { createCommand, getMainCommands } from "./input_api"; | ||
| import { CommandRequest } from "../data/request"; | ||
|
|
||
| const CommandInput = () => { | ||
| // TODO: (Member) Setup state and useEffect calls here | ||
| const [mainCommands, setMainCommands] = useState<MainCommandResponse[]>([]); | ||
|
|
||
| const handleSubmit = () => { | ||
| // TODO:(Member) Submit to your post endpoint | ||
| } | ||
| const [selectedCommandId, setSelectedCommandId] = useState<string>( | ||
| mainCommands[0].id.toString() | ||
| ); | ||
| const [commandParams, setCommandParams] = useState<string | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const getMainCommandsFn = async () => { | ||
| const data = await getMainCommands(); | ||
| setMainCommands(data.data); | ||
| setSelectedCommandId(data.data[0].id.toString()); | ||
| }; | ||
|
|
||
| getMainCommandsFn(); | ||
| }, []); | ||
|
|
||
| const handleSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
| const command: CommandRequest = { | ||
| command_type: selectedCommandId, | ||
| params: commandParams, | ||
| }; | ||
|
|
||
| createCommand(command); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <form> | ||
| <form onSubmit={handleSubmit}> | ||
| <div className="spreader"> | ||
| <div> | ||
| <label>Command Type: </label> | ||
| <select>{/* TODO: (Member) Display the list of commands based on the get commands request*/} | ||
| <option value={"1"}>Command 1</option> | ||
| <option value={"2"}>Command 2</option> | ||
| <option value={"3"}>Command 3</option> | ||
| <select onChange={(e) => setSelectedCommandId(e.target.value)}> | ||
| {/* TODO: (Member) Display the list of commands based on the get commands request*/} | ||
| {mainCommands.map((command) => ( | ||
| <option | ||
| key={command.id} | ||
| value={command.id} | ||
| > | ||
| {command.name} | ||
| </option> | ||
| ))} | ||
| </select> | ||
| </div> | ||
| <input /> {/* TODO: (Member) Add input handling here if the selected command has a param input*/} | ||
| <button onClick={handleSubmit}>Submit</button> | ||
| <input onChange={(e) => setCommandParams(e.target.value)} />{" "} | ||
| {/* TODO: (Member) Add input handling here if the selected command has a param input*/} | ||
| <button type="submit">Submit</button> | ||
| </div> | ||
| </form> | ||
| </> | ||
| ) | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| export default CommandInput; |
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.
Use
is Nonehere