Skip to content

Commit

Permalink
Merge pull request #276 from cmurp25/mainline
Browse files Browse the repository at this point in the history
Makerspace Website Bug Fixes + QoL Updates
  • Loading branch information
D42H5 authored Feb 3, 2025
2 parents 5520b33 + 63a8dd6 commit 70ae451
Show file tree
Hide file tree
Showing 11 changed files with 449 additions and 155 deletions.
21 changes: 21 additions & 0 deletions cdk/api_gateway/lambda_code/api_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,24 @@ def checkAndCleanRequestFields(data: dict, field_check):
pass

return data

def validTimestamp(timestamp: str) -> bool:
"""
Checks if a timestamp matches the TIMESTAMP_FORMAT.
:params timestamp: The timestamp to compare.
:returns: True if the timestamp matches the expected format.
False otherwise.
"""

# Parse the timestamp into a datetime object
try:
parsed = datetime.strptime(timestamp, TIMESTAMP_FORMAT)

# Timestamp not valid if an error occurs during parsing
except:
return False

# "Recreate" the timestamp from the parsed object according
# to the TIMESTAMP_FORMAT and compare it to the original
return timestamp == parsed.strftime(TIMESTAMP_FORMAT)
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,7 @@ def validateEquipmentRequestBody(self, data: dict):


# Ensure timestamp is in the correct format
try:
datetime.strptime(data['timestamp'], TIMESTAMP_FORMAT)
except ValueError:
if not validTimestamp(data['timestamp']):
errorMsg: str = f"Timestamp not in the approved format. Approved format is 'YYYY-MM-DDThh:mm:ss'."
raise InvalidRequestBody(errorMsg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,7 @@ def validateQualificationRequestBody(self, data: dict):
raise InvalidRequestBody(errorMsg)

# Ensure last_updated is in the correct format
try:
datetime.strptime(data['last_updated'], TIMESTAMP_FORMAT)
except ValueError:
if not validTimestamp(data['last_updated']):
errorMsg: str = f"Timestamp 'last_updated 'not in the approved format. Approved format is 'YYYY-MM-DDThh:mm:ss'."
raise InvalidRequestBody(errorMsg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

http = urllib3.PoolManager()

# Taken from api_gateway/lambda_code/api_defaults.py
BACKEND_TIMESTAMP_FORMAT: str = "%Y-%m-%dT%H:%M:%S"

# The bridge timestamp expects the seconds to be in milliseconds (3 decimal places)
BRIDGE_TIMESTAMP_FORMAT: str = "%Y-%m-%dT%H:%M:%S.%f"
# bridge also (as far as observed) only uses the timezone offset of -04:00
Expand Down Expand Up @@ -193,9 +190,9 @@ def get_completed_enrollments(self, bridge_url: str, auth_token: str,
# Get the user_id to use for the learner
user_id = learner_lookup[enrollment["links"]["learner"]["id"]]

# Convert updated_at timestamp to BACKEND_TIMESTAMP_FORMAT
# Convert updated_at timestamp to TIMESTAMP_FORMAT
updated_datetime = datetime.fromisoformat(enrollment['updated_at'])
last_updated = updated_datetime.strftime(BACKEND_TIMESTAMP_FORMAT)
last_updated = updated_datetime.strftime(TIMESTAMP_FORMAT)

# Update the learner's enrolled courses if they completed the course
if enrollment["state"].lower() == "complete":
Expand Down
4 changes: 1 addition & 3 deletions cdk/api_gateway/lambda_code/visits_handler/visits_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,7 @@ def validateVisitRequestBody(self, data: dict):
raise InvalidRequestBody(errorMsg)

# Ensure timestamp is in the correct format
try:
datetime.strptime(data['timestamp'], TIMESTAMP_FORMAT)
except ValueError:
if not validTimestamp(data['timestamp']):
errorMsg: str = f"Timestamp not in the approved format. Approved format is 'YYYY-MM-DDThh:mm:ss'."
raise InvalidRequestBody(errorMsg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const InitialInfo: React.FC<InitialInfoProps> = ({
</label>
<FormSelect
control={control}
name="printer_3d_info.printer_name"
name="printer_name"
values={printers}
/>
{errors.printer_name && (
Expand All @@ -141,7 +141,7 @@ const InitialInfo: React.FC<InitialInfoProps> = ({
className="form-control"
type="text"
placeholder="Enter a name for the print"
{...register("printer_3d_info.print_name")}
{...register("print_name")}
/>
{errors.print_name && (
<p className="text-danger">{errors.print_name.message}</p>
Expand All @@ -158,7 +158,7 @@ const InitialInfo: React.FC<InitialInfoProps> = ({
className="form-control"
type="text"
placeholder="Enter print duration"
{...register("printer_3d_info.print_duration")}
{...register("print_duration")}
/>
{errors.print_duration && (
<p className="text-danger">{errors.print_duration.message}</p>
Expand All @@ -178,10 +178,12 @@ const InitialInfo: React.FC<InitialInfoProps> = ({
className="form-control"
type="text"
placeholder="Enter print mass"
{...register("printer_3d_info.print_mass_estimate")}
{...register("print_mass_estimate")}
/>
{errors.print_mass && (
<p className="text-danger">{errors.print_mass.message}</p>
{errors.print_mass_estimate && (
<p className="text-danger">
{errors.print_mass_estimate.message}
</p>
)}
</div>
</>
Expand All @@ -200,7 +202,7 @@ const InitialInfo: React.FC<InitialInfoProps> = ({
className="form-control"
type="text"
placeholder="Enter resin volume"
{...register("printer_3d_info.resin_volume")}
{...register("resin_volume")}
/>
{errors.resin_volume && (
<p className="text-danger">{errors.resin_volume.message}</p>
Expand All @@ -214,7 +216,7 @@ const InitialInfo: React.FC<InitialInfoProps> = ({
</label>
<FormSelect
control={control}
name="printer_3d_info.resin_type"
name="resin_type"
values={["Clear", "Grey"]}
/>
{errors.resin_type && (
Expand Down
22 changes: 10 additions & 12 deletions site/visitor-console/src/pages/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ import EquipmentForm from "./EquipmentForm";
import Visits from "./Visits";
import EquipmentUsage from "./EquipmentUsage";

const App = () => {
useEffect(() => {
const config = getAmplifyConfig();
Amplify.configure({
Auth: {
Cognito: {
userPoolId: config.userPoolId,
userPoolClientId: config.userPoolClientId,
},
},
});
}, []);
const config = getAmplifyConfig();
Amplify.configure({
Auth: {
Cognito: {
userPoolId: config.userPoolId,
userPoolClientId: config.userPoolClientId,
},
},
});

const App = () => {
return (
<Router>
<Routes>
Expand Down
Loading

0 comments on commit 70ae451

Please sign in to comment.