Skip to content

Commit

Permalink
feat: added get uears (#123)
Browse files Browse the repository at this point in the history
* feat: added get uears

* feat: changed a structure

* chore: format
  • Loading branch information
hitohata authored Nov 19, 2024
1 parent 2fd9815 commit 99f124c
Showing 1 changed file with 34 additions and 1 deletion.
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

0 comments on commit 99f124c

Please sign in to comment.