From e508e0a916c08bd45a6ae94ce19aa66aa7e4996f Mon Sep 17 00:00:00 2001 From: Lucas Vas Date: Mon, 19 Jan 2026 12:44:51 -0500 Subject: [PATCH] chore: change to production tables This should be handled by environment variables in the future. --- src/main.rs | 4 ++++ src/pages/api/comparisons.rs | 2 +- src/pages/api/dates.rs | 7 +++++-- src/pages/api/scholarships.rs | 19 +++++++++---------- src/pages/scholarship_info.rs | 3 +-- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2900ec5..f24da6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,7 @@ +use axum::extract::State; +use axum::routing::post; +use leptos_axum::handle_server_fns_with_context; + #[cfg(feature = "ssr")] #[tokio::main] async fn main() { diff --git a/src/pages/api/comparisons.rs b/src/pages/api/comparisons.rs index 9177955..1022b1c 100644 --- a/src/pages/api/comparisons.rs +++ b/src/pages/api/comparisons.rs @@ -16,7 +16,7 @@ use leptos::prelude::ServerFnError; use leptos::server; #[cfg(feature = "ssr")] -static COMPARISONS_TABLE: &str = "leptos-comparison-test"; +static COMPARISONS_TABLE: &str = "leptos-comparisons"; /// Helper function to create all sports comparisons. Only used to create initial /// comparison data, and should be removed upon completion of a comparison editor page. diff --git a/src/pages/api/dates.rs b/src/pages/api/dates.rs index 12d5cdf..ee3a6a7 100644 --- a/src/pages/api/dates.rs +++ b/src/pages/api/dates.rs @@ -12,13 +12,16 @@ use aws_sdk_dynamodb::{ Client as DynamoClient }; +#[cfg(feature = "ssr")] +use crate::utils::server::create_dynamo_client; + #[cfg(feature = "ssr")] use std::sync::Arc; #[server] pub async fn create_dates(dates: Vec) -> Result<(), ServerFnError> { // Serialize and put dates into the database. - let client = expect_context::>(); + let client = create_dynamo_client().await; log!("Creating dates: {:?}", dates); @@ -51,7 +54,7 @@ pub async fn create_dates(dates: Vec) -> Result<(), ServerFnError> { #[server] pub async fn get_important_dates() -> Result, ServerFnError> { - let client = expect_context::>(); + let client = create_dynamo_client().await; client .scan() diff --git a/src/pages/api/scholarships.rs b/src/pages/api/scholarships.rs index 6a8b345..5101af6 100644 --- a/src/pages/api/scholarships.rs +++ b/src/pages/api/scholarships.rs @@ -18,9 +18,9 @@ use leptos::prelude::ServerFnError; use leptos::server; #[cfg(feature = "ssr")] -static SCHOLARSHIPS_TABLE: &str = "leptos-scholarship-test"; +static SCHOLARSHIPS_TABLE: &str = "leptos-scholarships"; -#[server(GetScholarshipInfo, endpoint = "/scholarship/info/get")] +#[server(GetScholarshipInfo)] pub async fn get_scholarship_info(id: String) -> Result { let client = create_dynamo_client().await; @@ -50,7 +50,7 @@ pub async fn get_scholarship_info(id: String) -> Result Result<(), ServerFnError> { use aws_sdk_dynamodb::error::ProvideErrorMetadata; @@ -73,7 +73,7 @@ pub async fn create_scholarship_info(info: ExpandableInfo) -> Result<(), ServerF } } -#[server(GetAllScholarshipInfo, endpoint = "/scholarship/info/get-all")] +#[server(GetAllScholarshipInfo)] pub async fn get_all_scholarship_info() -> Result, ServerFnError> { let client = create_dynamo_client().await; log!("Getting all scholarship info"); @@ -98,7 +98,7 @@ pub async fn get_all_scholarship_info() -> Result, ServerFnE } /// Gets all scholarships that are associated with the given scholarship provider's ID. -#[server(GetProviderScholarships, "/providers/scholarships/get")] +#[server(GetProviderScholarships)] pub async fn get_provider_scholarships(provider_id: String) -> Result, ServerFnError> { let client = create_dynamo_client().await; @@ -127,16 +127,15 @@ pub async fn get_provider_scholarships(provider_id: String) -> Result Result { +#[server(RegisterScholarship)] +pub async fn register_scholarship(provider_id: String) -> Result { let client = create_dynamo_client().await; log!("Creating scholarship for provider with ID {:?}", provider_id); - let mut current_uuid = "testing".to_string(); + let mut current_uuid = Uuid::new_v4().to_string(); let mut item = ExpandableInfo::new(current_uuid.clone()); item.data.insert("provider_id".to_string(), ValueType::String(Some(provider_id))); - item.data.insert("scholarship_name".to_string(), ValueType::String(Some(scholarship_name))); loop { let ser_item = serde_dynamo::to_item(&item)?; match client @@ -172,7 +171,7 @@ pub async fn register_scholarship(provider_id: String, scholarship_name: String) } /// Deletes a provider's scholarship given their provider ID and scholarship ID. -#[server(DeleteProviderScholarship, "/providers/scholarships/delete")] +#[server(DeleteProviderScholarship)] pub async fn delete_provider_scholarship(provider_id: String, scholarship_id: String) -> Result<(), ServerFnError> { let client = create_dynamo_client().await; diff --git a/src/pages/scholarship_info.rs b/src/pages/scholarship_info.rs index df793b4..7d561a4 100644 --- a/src/pages/scholarship_info.rs +++ b/src/pages/scholarship_info.rs @@ -128,8 +128,7 @@ fn ScholarshipList( // Button handlers let create_on_click = move |_| { create_action.dispatch(RegisterScholarship { - provider_id: provider_id.get().unwrap(), - scholarship_name: "Testing Scholarship".to_string() + provider_id: provider_id.get().unwrap() }); };