Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
BHouwens committed Jun 20, 2024
1 parent 75d65a2 commit 1b7fdb4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
8 changes: 6 additions & 2 deletions src/api/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ pub async fn get_data_handler<

// Check cache first
let mut cache_lock_result = cache.lock().await;
let cache_result: Result<Option<Vec<String>>, _> = cache_lock_result.get_data::<String>(address).await;
let cache_result: Result<Option<Vec<String>>, _> =
cache_lock_result.get_data::<String>(address).await;

info!("Cache result: {:?}", cache_result);

Expand All @@ -54,7 +55,10 @@ pub async fn get_data_handler<
match value {
Some(value) => {
info!("Data retrieved from cache");
let data = value.iter().map(|v| serde_json::from_str(v).unwrap()).collect::<Vec<Value>>();
let data = value
.iter()
.map(|v| serde_json::from_str(v).unwrap())
.collect::<Vec<Value>>();
return r.into_ok("Data retrieved successfully", json_serialize_embed(data));
}
None => {
Expand Down
28 changes: 13 additions & 15 deletions src/api/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@ pub async fn retrieve_from_db<D: KvStoreConnection + Clone + Send + 'static>(
let db_result: Result<Option<Vec<String>>, _> = db.lock().await.get_data(&address).await;

match db_result {
Ok(data) => {
match data {
Some(value) => {
info!("Data retrieved from DB");
let data = value
.iter()
.map(|v| serde_json::from_str(v).unwrap())
.collect::<Vec<Value>>();
return r.into_ok("Data retrieved successfully", json_serialize_embed(data));
}
None => {
info!("Data not found in DB");
return r.into_err_internal(ApiErrorType::Generic("Data not found".to_string()));
}
Ok(data) => match data {
Some(value) => {
info!("Data retrieved from DB");
let data = value
.iter()
.map(|v| serde_json::from_str(v).unwrap())
.collect::<Vec<Value>>();
return r.into_ok("Data retrieved successfully", json_serialize_embed(data));
}
}
None => {
info!("Data not found in DB");
return r.into_err_internal(ApiErrorType::Generic("Data not found".to_string()));
}
},
Err(_) => r.into_err_internal(ApiErrorType::Generic(
"Full Valence chain retrieval failed".to_string(),
)),
Expand Down

0 comments on commit 1b7fdb4

Please sign in to comment.