chore: revert StudentInfo fields to rustlang spec

This commit is contained in:
alphafetus committed 2025-08-29 18:20:21 -04:00
1 parent f4ab9c114c
commit 20dc3de187
2 files changed
+32 -18

No files matched your search

+6 -4
View File
@@ -7,17 +7,19 @@ use std::default::Default;
pub struct StudentInfo { pub struct StudentInfo {
/// The email address of the student. This was used in the previous version of the database, /// The email address of the student. This was used in the previous version of the database,
/// and should now be deprecated. /// and should now be deprecated.
///
/// This is the primary key of the table, and should not have a default value.
pub Email: String, pub Email: String,
/// The student's first name. /// The student's first name.
#[serde(default)] #[serde(default)]
pub studentFirstName: String, pub first_name: String,
/// The student's last name. /// The student's last name.
#[serde(default)] #[serde(default)]
pub studentLastName: String, pub last_name: String,
/// The student's highest math score on the SAT. /// The student's highest math score on the SAT.
#[serde(default)] #[serde(default)]
pub mathScoreSAT: i32, pub math_sat: i32,
/// The student's desired contact email. /// The student's desired contact email.
#[serde(default)] #[serde(default)]
pub studentEmail: String, pub contact_email: String,
} }
+26 -14
View File
@@ -1,3 +1,5 @@
use std::fmt::format;
// Server dependencies // Server dependencies
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
use aws_sdk_dynamodb::{error::ProvideErrorMetadata, types::AttributeValue, Client}; use aws_sdk_dynamodb::{error::ProvideErrorMetadata, types::AttributeValue, Client};
@@ -29,14 +31,16 @@ pub async fn get_submission(id: String) -> Result<StudentInfo, ServerFnError> {
.await .await
{ {
Ok(output) => { Ok(output) => {
let item = output.item.unwrap(); if let Some(item) = output.item {
console_log(format!("Found item from API: {item:?}").as_str());
let info: StudentInfo = from_item(item).unwrap(); Ok(from_item(item).unwrap())
} else {
console_log(format!("Got info from API: {:?}", info).as_str()); console_log("Couldn't find entry, returning default.");
let mut info = StudentInfo::default();
info.Email = id; // Set the correct subject
Ok(info) Ok(info)
} }
}
Err(err) => { Err(err) => {
let msg = err.message().unwrap_or("Unknown error"); let msg = err.message().unwrap_or("Unknown error");
Err(ServerFnError::new(msg)) Err(ServerFnError::new(msg))
@@ -56,14 +60,23 @@ pub async fn create_sample_submission(
// The put_item action can create or update an item in a DynamoDB table. // The put_item action can create or update an item in a DynamoDB table.
// It will completely replace any existing item with the same primary key, // It will completely replace any existing item with the same primary key,
// which is the desired behavior. // which is the desired behavior.
let item = to_item(student_info).unwrap(); let item = to_item(student_info.clone()).unwrap();
console_log(format!("Arguments for sample submission: {:?}", item).as_str());
match dbclient match dbclient
.put_item() .put_item()
.table_name("student-applications")
.set_item(Some(item)) .set_item(Some(item))
.send().await .send().await
{ {
Ok(_) => Ok(()), Ok(_) => {
Err(err) => Err(ServerFnError::new(err.into_service_error().to_string())), console_log(format!("Set up student information: {:?}", student_info).as_str());
Ok(())
},
Err(err) => {
let msg = err.message().unwrap_or("An unknown error occurred.");
console_log(format!("Error creating sample submission: {}", msg).as_str());
Err(ServerFnError::new(msg))
},
} }
} }
@@ -128,8 +141,7 @@ pub fn HomePage() -> impl IntoView {
<Row> <Row>
<p> <p>
"Current user's reported full name from the API: " "Current user's reported full name from the API: "
{reactive_info.studentFirstName}" " {reactive_info.first_name}" " {reactive_info.last_name}
{reactive_info.studentLastName}
</p> </p>
</Row> </Row>
<Row> <Row>
@@ -137,19 +149,19 @@ pub fn HomePage() -> impl IntoView {
label="First Name:" label="First Name:"
placeholder="John" placeholder="John"
disabled=elements_disabled disabled=elements_disabled
value=reactive_info.studentFirstName value=reactive_info.first_name
/> />
<OutlinedTextField <OutlinedTextField
label="Last Name:" label="Last Name:"
placeholder="Smith" placeholder="Smith"
disabled=elements_disabled disabled=elements_disabled
value=reactive_info.studentLastName value=reactive_info.last_name
/> />
<OutlinedTextField <OutlinedTextField
label="Contact Email" label="Contact Email"
placeholder="temp@region15.org" placeholder="temp@region15.org"
disabled=elements_disabled disabled=elements_disabled
value=reactive_info.studentEmail value=reactive_info.contact_email
/> />
</Row> </Row>
<Row> <Row>