feat: create functional dynamo query

This commit is contained in:
alphafetus committed 2025-05-23 16:10:32 -04:00
1 parent 07ae69c8ae
commit 40f12180e5
10 files changed
+34 -30

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ use leptos_router::{
StaticSegment, StaticSegment,
}; };
use crate::pages::{HomePage, AboutPage, ProviderEntry}; use crate::pages::{AboutPage, HomePage, ProviderEntry};
pub fn shell(options: LeptosOptions) -> impl IntoView { pub fn shell(options: LeptosOptions) -> impl IntoView {
view! { view! {
+1 -1
View File
@@ -1,4 +1,4 @@
use leptos::prelude::*; use leptos::prelude::*;
#[component] #[component]
pub fn ActionButton( pub fn ActionButton(
+2 -5
View File
@@ -1,7 +1,4 @@
mod action_button; mod action_button;
mod text_field; mod text_field;
pub use self::{ pub use self::{action_button::ActionButton, text_field::OutlinedTextField};
action_button::ActionButton,
text_field::OutlinedTextField
};
+2 -2
View File
@@ -1,10 +1,10 @@
use leptos::prelude::*; use leptos::prelude::*;
#[component] #[component]
pub fn OutlinedTextField( pub fn OutlinedTextField(
#[prop(default = String::from(""))] placeholder: String, #[prop(default = String::from(""))] placeholder: String,
#[prop(default = RwSignal::new("".to_string()))] value: RwSignal<String>, #[prop(default = RwSignal::new("".to_string()))] value: RwSignal<String>,
#[prop(default = RwSignal::new(false))] disabled: RwSignal<bool> #[prop(default = RwSignal::new(false))] disabled: RwSignal<bool>,
) -> impl IntoView { ) -> impl IntoView {
view! ( view! (
<input <input
+1 -1
View File
@@ -1,6 +1,6 @@
pub mod app; pub mod app;
mod pages;
mod components; mod components;
mod pages;
#[cfg(feature = "hydrate")] #[cfg(feature = "hydrate")]
#[wasm_bindgen::prelude::wasm_bindgen] #[wasm_bindgen::prelude::wasm_bindgen]
-1
View File
@@ -1,4 +1,3 @@
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
+1 -1
View File
@@ -1,4 +1,4 @@
use leptos::prelude::*; use leptos::prelude::*;
#[component] #[component]
pub fn AboutPage() -> impl IntoView { pub fn AboutPage() -> impl IntoView {
+23 -11
View File
@@ -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 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)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct StudentSubmission { pub struct StudentSubmission {
testing_value: Option<String> testing_value: Option<String>,
} }
#[server] #[server]
pub async fn create_sample_submission() -> Result<StudentSubmission, ServerFnError> { pub async fn create_sample_submission() -> Result<StudentSubmission, ServerFnError> {
let config = aws_config::load_defaults().await; use aws_sdk_dynamodb::{types::AttributeValue, Client};
let dbclient = aws_sdk_dynamodb::Client::new(&config);
let config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
let dbclient = Client::new(&config);
match dbclient match dbclient
.get_item() .get_item()
.table_name("student-applications") .table_name("student-applications")
.key("Email", dynamodb::model::AttributeValue::S("google_1234567".to_string())) .key("Email", AttributeValue::S("google_113247439743075864879".to_string()))
.send() .send()
.await .await
{ {
Ok(output) => { Ok(output) => {
println!("Found submission with passed key."); println!("Found submission with passed key.");
let value = output.item
.unwrap()
.get("studentFirstName").unwrap()
.as_s().unwrap().clone();
Ok(StudentSubmission { 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,8 +45,14 @@ pub fn HomePage() -> impl IntoView {
let on_click = move |_| { let on_click = move |_| {
*count.write() += 1; *count.write() += 1;
*elements_disabled.write() = count.get() == 10; *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::<CreateSampleSubmission>::new();
view! { view! {
<h1>"Welcome to Leptos!"</h1> <h1>"Welcome to Leptos!"</h1>
+2 -6
View File
@@ -1,9 +1,5 @@
mod home_page;
mod about_page; mod about_page;
mod home_page;
mod provider_entry; mod provider_entry;
pub use self::{ pub use self::{about_page::*, home_page::*, provider_entry::*};
home_page::*,
about_page::*,
provider_entry::*,
};
+1 -1
View File
@@ -1,4 +1,4 @@
use leptos::prelude::*; use leptos::prelude::*;
#[component] #[component]
pub fn ProviderEntry() -> impl IntoView { pub fn ProviderEntry() -> impl IntoView {