-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* convert from using tokens to using api keys * convert frontend to only use api keys instead of refresh tokens * call the logout endpoint * Add back google authentication * fix lint * add otp wrapper * add config fields * added robot backend * hooked up robot backend to frontend * Connected robots page and individual robots to the dynamodb local backend * connected parts and robots frontend to local dynamodb backend * added create robot * minor fixes * fix everything * only add necessary cors stuff * frnotend improvements for robocreation button * change add robot path * hooks/rob -> hooks/api * delete unwanted dynamodb global var * Fix dynamodb -> Crud TODO: move crud methods into helper crud * email_utils -> utils/email * fix add_robot -> add/robot * fix add_robot -> add/robot * samesite lax * insert actual user id * fix all for real * pass tests --------- Co-authored-by: Isaac Light <[email protected]>
- Loading branch information
1 parent
acc0475
commit 9f6032e
Showing
15 changed files
with
726 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import axios from "axios"; | ||
|
||
export interface PurchaseLink { | ||
url: string; | ||
price: number; | ||
name: string; | ||
} | ||
|
||
export interface UsedBy { | ||
name: string; | ||
id: string; | ||
stars: number; | ||
} | ||
|
||
export interface Part { | ||
name: string; | ||
owner: string; | ||
description: string; | ||
images: Image[]; | ||
part_id: string; | ||
used_by: UsedBy[]; | ||
purchase_links: PurchaseLink[]; | ||
} | ||
|
||
export interface Bom { | ||
id: string; | ||
name: string; | ||
quantity: number; | ||
price: number; | ||
} | ||
|
||
export interface Image { | ||
caption: string; | ||
url: string; | ||
} | ||
|
||
export interface Robot { | ||
robot_id: string; | ||
name: string; | ||
description: string; | ||
owner: string; | ||
bom: Bom[]; | ||
images: Image[]; | ||
} | ||
|
||
class api { | ||
private api; | ||
|
||
constructor(baseURL: string | undefined) { | ||
this.api = axios.create({ | ||
baseURL, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
withCredentials: true, // Ensure credentials are sent | ||
}); | ||
} | ||
public async getRobots(): Promise<Robot[]> { | ||
try { | ||
const response = await this.api.get("/robots"); | ||
return response.data; | ||
} catch (error) { | ||
if (axios.isAxiosError(error)) { | ||
console.error("Error fetching robots:", error.response?.data); | ||
throw new Error( | ||
error.response?.data?.detail || "Error fetching robots", | ||
); | ||
} else { | ||
console.error("Unexpected error:", error); | ||
throw new Error("Unexpected error"); | ||
} | ||
} | ||
} | ||
public async getRobotById(robotId: string | undefined): Promise<Robot> { | ||
try { | ||
const response = await this.api.get(`/robots/${robotId}`); | ||
return response.data; | ||
} catch (error) { | ||
if (axios.isAxiosError(error)) { | ||
console.error("Error fetching robot:", error.response?.data); | ||
throw new Error(error.response?.data?.detail || "Error fetching robot"); | ||
} else { | ||
console.error("Unexpected error:", error); | ||
throw new Error("Unexpected error"); | ||
} | ||
} | ||
} | ||
public async getPartById(partId: string | undefined): Promise<Part> { | ||
try { | ||
const response = await this.api.get(`/parts/${partId}`); | ||
return response.data; | ||
} catch (error) { | ||
if (axios.isAxiosError(error)) { | ||
console.error("Error fetching robot:", error.response?.data); | ||
throw new Error(error.response?.data?.detail || "Error fetching robot"); | ||
} else { | ||
console.error("Unexpected error:", error); | ||
throw new Error("Unexpected error"); | ||
} | ||
} | ||
} | ||
public async addRobot(robot: Robot): Promise<void> { | ||
const s = robot.name; | ||
try { | ||
await this.api.post("/add/robot/", robot); | ||
} catch (error) { | ||
if (axios.isAxiosError(error)) { | ||
console.error("Error adding robot:", error.response?.data); | ||
throw new Error( | ||
error.response?.data?.detail || "Error adding robot " + s, | ||
); | ||
} else { | ||
console.error("Unexpected error:", error); | ||
throw new Error("Unexpected error"); | ||
} | ||
} | ||
} | ||
public async getParts(): Promise<Part[]> { | ||
try { | ||
const response = await this.api.get("/parts"); | ||
return response.data; | ||
} catch (error) { | ||
if (axios.isAxiosError(error)) { | ||
console.error("Error fetching parts:", error.response?.data); | ||
throw new Error(error.response?.data?.detail || "Error fetching parts"); | ||
} else { | ||
console.error("Unexpected error:", error); | ||
throw new Error("Unexpected error"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default new api("http://127.0.0.1:8080/api"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.