From 40f12180e55d144e5f9637586a35f300818aaca2 Mon Sep 17 00:00:00 2001 From: Lucas Vas Date: Fri, 23 May 2025 16:10:32 -0400 Subject: [PATCH] feat: create functional dynamo query --- src/app.rs | 2 +- src/components/action_button.rs | 2 +- src/components/mod.rs | 7 ++----- src/components/text_field.rs | 4 ++-- src/lib.rs | 2 +- src/main.rs | 1 - src/pages/about_page.rs | 2 +- src/pages/home_page.rs | 36 ++++++++++++++++++++++----------- src/pages/mod.rs | 8 ++------ src/pages/provider_entry.rs | 4 ++-- 10 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/app.rs b/src/app.rs index f65c0ba..5fd2cbe 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,7 +5,7 @@ use leptos_router::{ StaticSegment, }; -use crate::pages::{HomePage, AboutPage, ProviderEntry}; +use crate::pages::{AboutPage, HomePage, ProviderEntry}; pub fn shell(options: LeptosOptions) -> impl IntoView { view! { diff --git a/src/components/action_button.rs b/src/components/action_button.rs index 34f4f86..54088eb 100644 --- a/src/components/action_button.rs +++ b/src/components/action_button.rs @@ -1,4 +1,4 @@ -use leptos::prelude::*; +use leptos::prelude::*; #[component] pub fn ActionButton( diff --git a/src/components/mod.rs b/src/components/mod.rs index d91739d..6784b67 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -1,7 +1,4 @@ -mod action_button; +mod action_button; mod text_field; -pub use self::{ - action_button::ActionButton, - text_field::OutlinedTextField -}; \ No newline at end of file +pub use self::{action_button::ActionButton, text_field::OutlinedTextField}; diff --git a/src/components/text_field.rs b/src/components/text_field.rs index 94a4428..31fe327 100644 --- a/src/components/text_field.rs +++ b/src/components/text_field.rs @@ -1,10 +1,10 @@ -use leptos::prelude::*; +use leptos::prelude::*; #[component] pub fn OutlinedTextField( #[prop(default = String::from(""))] placeholder: String, #[prop(default = RwSignal::new("".to_string()))] value: RwSignal, - #[prop(default = RwSignal::new(false))] disabled: RwSignal + #[prop(default = RwSignal::new(false))] disabled: RwSignal, ) -> impl IntoView { view! ( impl IntoView { diff --git a/src/pages/home_page.rs b/src/pages/home_page.rs index da94b38..8162c7e 100644 --- a/src/pages/home_page.rs +++ b/src/pages/home_page.rs @@ -1,33 +1,39 @@ -use leptos::prelude::*; -use aws_sdk_dynamodb as dynamodb; -use aws_sdk_dynamodb::operation::get_item::GetItemOutput; -use leptos::server_fn::serde::{Serialize, Deserialize}; use crate::components::{ActionButton, OutlinedTextField}; +use leptos::prelude::*; +use leptos::leptos_dom::logging::console_log; +use leptos::task::spawn_local; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct StudentSubmission { - testing_value: Option + testing_value: Option, } #[server] pub async fn create_sample_submission() -> Result { - let config = aws_config::load_defaults().await; - let dbclient = aws_sdk_dynamodb::Client::new(&config); + use aws_sdk_dynamodb::{types::AttributeValue, Client}; + + let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await; + let dbclient = Client::new(&config); match dbclient .get_item() .table_name("student-applications") - .key("Email", dynamodb::model::AttributeValue::S("google_1234567".to_string())) + .key("Email", AttributeValue::S("google_113247439743075864879".to_string())) .send() .await { Ok(output) => { println!("Found submission with passed key."); + let value = output.item + .unwrap() + .get("studentFirstName").unwrap() + .as_s().unwrap().clone(); Ok(StudentSubmission { - testing_value: None + testing_value: Some(value), }) } - Err(e) => Err(Error::unhandled(e)) + Err(e) => Err(ServerFnError::new("Couldn't find a submission with that ID.")) } } @@ -39,12 +45,18 @@ pub fn HomePage() -> impl IntoView { let on_click = move |_| { *count.write() += 1; *elements_disabled.write() = count.get() == 10; + spawn_local(async { + let response = create_sample_submission().await; + match response { + Ok(submission) => console_log(submission.testing_value.unwrap_or("Default value.".to_string()).as_str()), + Err(_) => console_log("Failed to get correct information.") + }; + }); }; - let get_submission = ServerAction::::new(); view! {

"Welcome to Leptos!"

- "Click Me: " {count} diff --git a/src/pages/mod.rs b/src/pages/mod.rs index 9292f57..47a8092 100644 --- a/src/pages/mod.rs +++ b/src/pages/mod.rs @@ -1,9 +1,5 @@ -mod home_page; mod about_page; +mod home_page; mod provider_entry; -pub use self::{ - home_page::*, - about_page::*, - provider_entry::*, -}; \ No newline at end of file +pub use self::{about_page::*, home_page::*, provider_entry::*}; diff --git a/src/pages/provider_entry.rs b/src/pages/provider_entry.rs index 65824c5..fa444ab 100644 --- a/src/pages/provider_entry.rs +++ b/src/pages/provider_entry.rs @@ -1,4 +1,4 @@ -use leptos::prelude::*; +use leptos::prelude::*; #[component] pub fn ProviderEntry() -> impl IntoView { @@ -6,4 +6,4 @@ pub fn ProviderEntry() -> impl IntoView {

This is the provider entry page

It would usually have a series of questions that we ask the providers

) -} \ No newline at end of file +}