Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Return request extension for POST request (#17)
Browse files Browse the repository at this point in the history
* Return request extension for POST request

* Make clippy happy
  • Loading branch information
adrianEffe authored Aug 15, 2023
1 parent c58bf96 commit 84db442
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/routes/full_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@ use uuid::Uuid;
pub async fn full_url(
State(data): State<Arc<AppState>>,
Json(payload): Json<CreateShortUrlSchema>,
) {
) -> String {
let mut retry_count = 3;

while retry_count > 0 {
let query_result = insert_in_db(&payload.url, State(data.clone())).await;

match query_result {
Ok(note) => {
println!("okay received testing: {:?}", note);
break;
Ok(request) => {
println!("okay received testing: {:?}", request);
return request.extension;
}
Err(e) => {
println!("failed with error: {:?}", e);
//TODO : - For now assume is failing because of error code 23505, that stands for
//duplicate key
retry_count += 1;
if retry_count == 1 {
return "error".to_string();
}
retry_count -= 1;
}
}
}

"internal server error".to_string()
}

async fn insert_in_db(
Expand Down

0 comments on commit 84db442

Please sign in to comment.