feat: create static global constants for table names
This commit is contained in:
1 parent
5f6e0edab2
commit
8af64cbf35
3 files changed
+18
-11
No files matched your search
@@ -15,6 +15,8 @@ use crate::common::{
|
|||||||
use leptos::prelude::ServerFnError;
|
use leptos::prelude::ServerFnError;
|
||||||
use leptos::server;
|
use leptos::server;
|
||||||
|
|
||||||
|
static COMPARISONS_TABLE: &str = "leptos-comparison-test";
|
||||||
|
|
||||||
/// Helper function to create all sports comparisons. Only used to create initial
|
/// 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.
|
/// comparison data, and should be removed upon completion of a comparison editor page.
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
@@ -386,7 +388,7 @@ pub async fn create_test_comparisons() -> Result<(), ServerFnError> {
|
|||||||
for comparison in comp_list {
|
for comparison in comp_list {
|
||||||
if let Err(err) = client
|
if let Err(err) = client
|
||||||
.put_item()
|
.put_item()
|
||||||
.table_name("leptos-comparison-test")
|
.table_name(COMPARISONS_TABLE)
|
||||||
.set_item(Some(serde_dynamo::to_item(&comparison)?))
|
.set_item(Some(serde_dynamo::to_item(&comparison)?))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
@@ -409,7 +411,7 @@ pub async fn get_comparison_info() -> Result<Vec<ComparisonData>, ServerFnError>
|
|||||||
// id and display text, but we'll return the whole thing.
|
// id and display text, but we'll return the whole thing.
|
||||||
match client
|
match client
|
||||||
.scan()
|
.scan()
|
||||||
.table_name("leptos-comparison-test")
|
.table_name(COMPARISONS_TABLE)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -435,7 +437,7 @@ pub async fn get_comparisons_categorized() -> Result<HashMap<String, Vec<Compari
|
|||||||
|
|
||||||
match client
|
match client
|
||||||
.scan()
|
.scan()
|
||||||
.table_name("leptos-comparison-test")
|
.table_name(COMPARISONS_TABLE)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ use crate::common::ExpandableInfo;
|
|||||||
use leptos::prelude::ServerFnError;
|
use leptos::prelude::ServerFnError;
|
||||||
use leptos::server;
|
use leptos::server;
|
||||||
|
|
||||||
|
static SCHOLARSHIPS_TABLE: &str = "leptos-scholarship-test";
|
||||||
|
|
||||||
#[server(GetScholarshipInfo, endpoint = "/scholarship/info/get")]
|
#[server(GetScholarshipInfo, endpoint = "/scholarship/info/get")]
|
||||||
pub async fn get_scholarship_info(id: String) -> Result<ExpandableInfo, ServerFnError> {
|
pub async fn get_scholarship_info(id: String) -> Result<ExpandableInfo, ServerFnError> {
|
||||||
let client = create_dynamo_client().await;
|
let client = create_dynamo_client().await;
|
||||||
@@ -26,7 +28,7 @@ pub async fn get_scholarship_info(id: String) -> Result<ExpandableInfo, ServerFn
|
|||||||
log!("Getting scholarship info using id {:?}", id);
|
log!("Getting scholarship info using id {:?}", id);
|
||||||
match client
|
match client
|
||||||
.get_item()
|
.get_item()
|
||||||
.table_name("leptos-scholarship-test")
|
.table_name(SCHOLARSHIPS_TABLE)
|
||||||
.key("subject", AttributeValue::S(id.clone()))
|
.key("subject", AttributeValue::S(id.clone()))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
@@ -58,7 +60,7 @@ pub async fn create_scholarship_info(info: ExpandableInfo) -> Result<(), ServerF
|
|||||||
|
|
||||||
match client
|
match client
|
||||||
.put_item()
|
.put_item()
|
||||||
.table_name("leptos-scholarship-test")
|
.table_name(SCHOLARSHIPS_TABLE)
|
||||||
.set_item(Some(serde_dynamo::to_item(&info)?))
|
.set_item(Some(serde_dynamo::to_item(&info)?))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
@@ -77,7 +79,7 @@ pub async fn get_all_scholarship_info() -> Result<Vec<ExpandableInfo>, ServerFnE
|
|||||||
log!("Getting all scholarship info");
|
log!("Getting all scholarship info");
|
||||||
match client
|
match client
|
||||||
.scan()
|
.scan()
|
||||||
.table_name("leptos-scholarship-test")
|
.table_name(SCHOLARSHIPS_TABLE)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
@@ -104,7 +106,7 @@ pub async fn get_provider_scholarships(provider_id: String) -> Result<Vec<Expand
|
|||||||
|
|
||||||
match client
|
match client
|
||||||
.scan()
|
.scan()
|
||||||
.table_name("leptos-scholarship-test")
|
.table_name(SCHOLARSHIPS_TABLE)
|
||||||
.expression_attribute_values(":id", serde_dynamo::to_attribute_value(ValueType::String(Some(provider_id)))?)
|
.expression_attribute_values(":id", serde_dynamo::to_attribute_value(ValueType::String(Some(provider_id)))?)
|
||||||
.filter_expression("provider_id = :id")
|
.filter_expression("provider_id = :id")
|
||||||
.send()
|
.send()
|
||||||
@@ -139,7 +141,7 @@ pub async fn register_scholarship(provider_id: String, scholarship_name: String)
|
|||||||
let ser_item = serde_dynamo::to_item(&item)?;
|
let ser_item = serde_dynamo::to_item(&item)?;
|
||||||
match client
|
match client
|
||||||
.put_item()
|
.put_item()
|
||||||
.table_name("leptos-scholarship-test")
|
.table_name(SCHOLARSHIPS_TABLE)
|
||||||
.set_item(Some(ser_item))
|
.set_item(Some(ser_item))
|
||||||
.condition_expression("attribute_not_exists(subject)")
|
.condition_expression("attribute_not_exists(subject)")
|
||||||
.send()
|
.send()
|
||||||
@@ -180,7 +182,7 @@ pub async fn delete_provider_scholarship(provider_id: String, scholarship_id: St
|
|||||||
// otherwise everyone can delete anyone else's scholarships.
|
// otherwise everyone can delete anyone else's scholarships.
|
||||||
match client
|
match client
|
||||||
.delete_item()
|
.delete_item()
|
||||||
.table_name("leptos-scholarship-test")
|
.table_name(SCHOLARSHIPS_TABLE)
|
||||||
.key("subject", AttributeValue::S(scholarship_id))
|
.key("subject", AttributeValue::S(scholarship_id))
|
||||||
.expression_attribute_values(":provider_id", serde_dynamo::to_attribute_value(ValueType::String(Some(provider_id)))?)
|
.expression_attribute_values(":provider_id", serde_dynamo::to_attribute_value(ValueType::String(Some(provider_id)))?)
|
||||||
.condition_expression("provider_id = :provider_id")
|
.condition_expression("provider_id = :provider_id")
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ use crate::pages::utils::get_user_claims;
|
|||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
use crate::pages::utils::server_utils::create_dynamo_client;
|
use crate::pages::utils::server_utils::create_dynamo_client;
|
||||||
|
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
static PROVIDER_CONTACT_TABLE: &str = "leptos-provider-contacts";
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
async fn get_provider_contact(id: String) -> Result<HashMap<String, ValueType>, ServerFnError> {
|
async fn get_provider_contact(id: String) -> Result<HashMap<String, ValueType>, ServerFnError> {
|
||||||
use aws_sdk_dynamodb::types::AttributeValue;
|
use aws_sdk_dynamodb::types::AttributeValue;
|
||||||
@@ -21,7 +24,7 @@ async fn get_provider_contact(id: String) -> Result<HashMap<String, ValueType>,
|
|||||||
|
|
||||||
match client
|
match client
|
||||||
.get_item()
|
.get_item()
|
||||||
.table_name("leptos-provider-contacts")
|
.table_name(PROVIDER_CONTACT_TABLE)
|
||||||
.key("subject", AttributeValue::S(id))
|
.key("subject", AttributeValue::S(id))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
@@ -58,7 +61,7 @@ async fn put_provider_contact(id: String, contact_info: HashMap<String, ValueTyp
|
|||||||
|
|
||||||
match client
|
match client
|
||||||
.put_item()
|
.put_item()
|
||||||
.table_name("leptos-provider-contacts")
|
.table_name(PROVIDER_CONTACT_TABLE)
|
||||||
.set_item(Some(item))
|
.set_item(Some(item))
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in new issue
Block a user