From daa7aea33439a91c4dd14592d1909d78ebe472e2 Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Mon, 20 Jan 2025 13:33:39 +0100 Subject: replace useless function (check_if_exists) --- src/routes/album.rs | 13 +++---------- src/routes/artist.rs | 11 ++--------- src/routes/song.rs | 15 ++++----------- 3 files changed, 9 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/routes/album.rs b/src/routes/album.rs index d826f24..6f793bd 100644 --- a/src/routes/album.rs +++ b/src/routes/album.rs @@ -17,15 +17,15 @@ pub async fn album( ) -> HttpResponse { let default: String = String::from(""); let search_attempt: sqlx::Result, sqlx::Error> = match true { - _ if check_if_exists(&get_args.id) => { + _ if get_args.id.is_some() => { let id: &str = &get_args.id.as_ref().unwrap_or(&default); app_state.database.select_album_by_id(id).await } - _ if check_if_exists(&get_args.name) => { + _ if get_args.name.is_some() => { let name: &str = &get_args.name.as_ref().unwrap_or(&default); app_state.database.select_albums_by_name(name).await } - _ if check_if_exists(&get_args.artist) => { + _ if get_args.artist.is_some() => { let artist: &str = &get_args.artist.as_ref().unwrap_or(&default); app_state.database.select_albums_by_artist(artist).await } @@ -37,10 +37,3 @@ pub async fn album( Err(e) => HttpResponse::Ok().body(format!("{}", e)), } } - -fn check_if_exists(value: &Option) -> bool { - match value { - Some(_) => true, - None => false, - } -} diff --git a/src/routes/artist.rs b/src/routes/artist.rs index 5f0b9a6..18272fb 100644 --- a/src/routes/artist.rs +++ b/src/routes/artist.rs @@ -16,12 +16,12 @@ pub async fn artist( ) -> HttpResponse { let default: String = String::from(""); let search_attempt: sqlx::Result, sqlx::Error> = match true { - _ if check_if_exists(&get_args.id) => { + _ if get_args.id.is_some() => { let id: &str = &get_args.id.as_ref().unwrap_or(&default); app_state.database.select_artist_by_id(id).await } - _ if check_if_exists(&get_args.name) => { + _ if get_args.name.is_some() => { let name: &str = &get_args.name.as_ref().unwrap_or(&default); app_state.database.select_artists_by_name(name).await } @@ -33,10 +33,3 @@ pub async fn artist( Err(e) => HttpResponse::Ok().body(format!("{}", e)), } } - -fn check_if_exists(value: &Option) -> bool { - match value { - Some(_) => true, - None => false, - } -} diff --git a/src/routes/song.rs b/src/routes/song.rs index 8cb34bf..27197dd 100644 --- a/src/routes/song.rs +++ b/src/routes/song.rs @@ -18,19 +18,19 @@ pub async fn song( ) -> HttpResponse { let default: String = String::from(""); let search_attempt: sqlx::Result> = match true { - _ if check_if_exists(&get_args.id) => { + _ if get_args.id.is_some() => { let id: &str = &get_args.id.as_ref().unwrap_or(&default); app_state.database.select_song_by_id(id).await } - _ if check_if_exists(&get_args.name) => { + _ if get_args.name.is_some() => { let name: &str = &get_args.name.as_ref().unwrap_or(&default); app_state.database.select_songs_by_name(name).await } - _ if check_if_exists(&get_args.album) => { + _ if get_args.album.is_some() => { let album: &str = &get_args.album.as_ref().unwrap_or(&default); app_state.database.select_songs_by_album(album).await } - _ if check_if_exists(&get_args.artist) => { + _ if get_args.artist.is_some() => { let artist: &str = &get_args.artist.as_ref().unwrap_or(&default); app_state.database.select_songs_by_artist(artist).await } @@ -42,10 +42,3 @@ pub async fn song( Err(e) => HttpResponse::Ok().body(format!("{}", e)), } } - -fn check_if_exists(value: &Option) -> bool { - match value { - Some(_) => true, - None => false, - } -} -- cgit v1.2.3