Skip to content

Commit

Permalink
enh: replaces print to info logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypalmudaliyar24 committed Jun 28, 2024
1 parent f80083a commit 7b54bd5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions crates/url_shortner/src/domain/action/internal/crud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ use rand::{
};
use reqwest::Url;
use shared::redis::types::RedisConnectionPool;
use tracing::*;

pub async fn generate_url(
app_state: Data<AppState>,
req: GenerateShortUrlRequest,
) -> Result<GenerateShortUrlResponse, AppError> {
println!("Generate short url req: {:?}", req);
info!("Generate short url req: {:?}", req);

let base_url = Url::parse(&req.base_url)
.map_err(|error| AppError::InvalidRequest(format!("URL parsing failed: {}", error)))?;

println!("Parsed URL: {:?}", base_url);
info!("Parsed URL: {:?}", base_url);

let expiry_seconds: Option<u32> = req
.expiry_in_hours
Expand Down Expand Up @@ -65,7 +66,7 @@ pub async fn generate_url(

let url_expiry = TimeStamp(Utc::now() + Duration::seconds(redis_expiry_in_s.into()));
let short_url = format!("{}/{}", app_state.shortened_base_url, final_short_code);
println!(
info!(
"Generated short url: {} with expiry ts: {:?}",
short_url, url_expiry.0
);
Expand Down
5 changes: 3 additions & 2 deletions crates/url_shortner/src/domain/action/public_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ use crate::{
common::types::UrlShortCode, environment::AppState, redis::commands::*, tools::error::AppError,
};
use actix_web::web::{Data, Redirect};
use tracing::*;

pub async fn redirect_to_url(
app_state: Data<AppState>,
url_short_code: UrlShortCode,
) -> Result<Redirect, AppError> {
println!(
info!(
"redirect request to url with short code: {:?}",
url_short_code
);
Expand All @@ -24,7 +25,7 @@ pub async fn redirect_to_url(

match mb_base_url {
Some(base_url) => {
println!("redirecting to: {}", base_url);
info!("redirecting to: {}", base_url);
Ok(Redirect::to(base_url.to_string()))
}
None => Err(AppError::InvalidRequest(format!(
Expand Down

0 comments on commit 7b54bd5

Please sign in to comment.