-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Isaac Light
authored and
Isaac Light
committed
Jun 2, 2024
1 parent
943cd4d
commit 65a5354
Showing
9 changed files
with
227 additions
and
64 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,26 @@ | ||
import axios from "axios"; | ||
|
||
class rob { | ||
private api; | ||
|
||
constructor(baseURL: string | undefined) { | ||
this.api = axios.create({ baseURL }); | ||
} | ||
|
||
public async getRobotById(robotId: string | undefined): Promise<any> { | ||
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"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default new rob("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
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,39 @@ | ||
# from typing import Union | ||
|
||
# import boto3 | ||
# from botocore.exceptions import ClientError | ||
# from fastapi import FastAPI, HTTPException | ||
# from pydantic import BaseModel | ||
|
||
# app = FastAPI() | ||
|
||
# # Configure your DynamoDB client | ||
# dynamodb = boto3.resource( | ||
# "dynamodb", | ||
# region_name="us-east-1", # Replace with your AWS region | ||
# aws_access_key_id="test", # Replace with your AWS access key | ||
# aws_secret_access_key="test", # Replace with your AWS secret key | ||
# ) | ||
|
||
# # Replace 'Robots' with your DynamoDB table name | ||
# table = dynamodb.Table("Robots") | ||
|
||
|
||
# class Robot(BaseModel): | ||
# robot_id: str | ||
# name: str | ||
# description: str | ||
# owner: str | ||
|
||
|
||
# @app.get("/robots/{robot_id}", response_model=Robot) | ||
# async def get_robot(robot_id: str) -> Union[Robot, HTTPException]: | ||
# try: | ||
# response = table.get_item(Key={"robot_id": robot_id}) | ||
# if "Item" in response: | ||
# robot = response["Item"] | ||
# return Robot(**robot) | ||
# else: | ||
# raise HTTPException(status_code=404, detail="Robot not found") | ||
# except ClientError as e: | ||
# raise HTTPException(status_code=500, detail=e.response["Error"]["Message"]) |
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
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,20 @@ | ||
import boto3 | ||
from botocore.exceptions import NoCredentialsError, PartialCredentialsError | ||
|
||
|
||
def test_dynamodb_connection() -> None: | ||
try: | ||
# Initialize DynamoDB client | ||
dynamodb = boto3.resource('dynamodb') | ||
# Attempt to list tables as a test | ||
tables = list(dynamodb.tables.all()) | ||
print(f"Connected to DynamoDB. Found tables: {[table.name for table in tables]}") | ||
except NoCredentialsError: | ||
print("No credentials found. Please configure your AWS credentials.") | ||
except PartialCredentialsError: | ||
print("Incomplete credentials found. Please check your AWS credentials.") | ||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
|
||
if __name__ == "__main__": | ||
test_dynamodb_connection() |
File renamed without changes.