Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added get uears #123

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion crates/aws_clients/src/dynamodb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub mod client {

impl GetFileListTrait for DynamoDbClient {
async fn get_years() -> Result<Vec<String>, String> {
Ok(vec![])
get_date_list("root").await
}

async fn get_month(_years: usize) -> Result<Vec<String>, String> {
Expand Down Expand Up @@ -110,6 +110,39 @@ pub mod client {
}
}

async fn get_date_list(key: &str) -> Result<Vec<String>, String> {
let request = dynamodb_client()
.await
.get_item()
.table_name(table_name())
.key("PK", AttributeValue::S(key.to_string()))
.key("SK", AttributeValue::N("0".to_string()));

let saved_date = match request.send().await {
Ok(result) => match result.item {
None => return Ok(Vec::new()),
Some(item) => match item.get_key_value("SavedDate") {
None => return Err("Saved date is not found".to_string()),
Some(val) => match val.1.as_l() {
Ok(attribute) => attribute.to_owned(),
Err(_) => return Err("Casting to list is failed.".to_string()),
},
},
},
Err(e) => return Err(e.to_string()),
};

let mut date = Vec::new();

for attribute in saved_date {
match attribute.as_s() {
Ok(s) => date.push(s.to_owned()),
Err(_) => return Err("Invalid date is stored".to_string()),
}
}
Ok(date)
}

/// this is a helper function.
/// if there is argument, this function returns it.
/// If not, this function gets system time.
Expand Down
Loading