summaryrefslogtreecommitdiff
path: root/src/routes/album.rs
diff options
context:
space:
mode:
authorniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2025-01-20 00:13:45 +0100
committerniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2025-01-20 00:13:45 +0100
commit44833bc898cac0612907613ed64ee4ff2a94a5c8 (patch)
tree5bb8f355ebeabeead47495f05d00a186d2e06960 /src/routes/album.rs
parented0f5925de1931a13e6713d73e174a5362fc5d68 (diff)
complete database rework
Diffstat (limited to 'src/routes/album.rs')
-rw-r--r--src/routes/album.rs66
1 files changed, 15 insertions, 51 deletions
diff --git a/src/routes/album.rs b/src/routes/album.rs
index 02116d4..c06d4d2 100644
--- a/src/routes/album.rs
+++ b/src/routes/album.rs
@@ -1,4 +1,4 @@
-use crate::routes::Album;
+use crate::database::Album;
use crate::AppState;
use actix_web::{get, web, HttpResponse};
use serde::Deserialize;
@@ -15,62 +15,26 @@ pub async fn album(
app_state: web::Data<AppState>,
get_args: web::Query<AlbumQueryOptions>,
) -> HttpResponse {
- let search_attempt: sqlx::Result<Vec<Album>>;
-
- match true {
+ let search_attempt: sqlx::Result<Vec<Album>, sqlx::Error> = match true {
_ if check_if_exists(&get_args.id) => {
- search_attempt = sqlx::query_as!(
- Album,
- "SELECT album.name, album.id,
- artist.name as artist_name, artist.id as artist_id
- FROM album
- INNER JOIN artist ON album.artist_id = artist.id
- WHERE album.id=?",
- &get_args.id,
- )
- .fetch_all(&app_state.pool)
- .await;
+ app_state
+ .database
+ .select_album_by_id(&get_args.id.clone().unwrap())
+ .await
}
_ if check_if_exists(&get_args.name) => {
- let new_name : String = format!("{}{}{}", "%", &get_args.name.clone().unwrap(), "%");
- search_attempt = sqlx::query_as!(
- Album,
- "SELECT album.name, album.id,
- artist.name as artist_name, artist.id as artist_id
- FROM album
- INNER JOIN artist ON album.artist_id = artist.id
- WHERE LOWER(album.name) LIKE LOWER(?)",
- new_name,
- )
- .fetch_all(&app_state.pool)
- .await;
+ app_state
+ .database
+ .select_albums_by_name(&get_args.name.clone().unwrap())
+ .await
}
_ if check_if_exists(&get_args.artist) => {
- search_attempt = sqlx::query_as!(
- Album,
- "SELECT album.name, album.id,
- artist.name as artist_name, artist.id as artist_id
- FROM album
- INNER JOIN artist ON album.artist_id = artist.id
- WHERE album.artist_id=?
- ",
- &get_args.artist,
- )
- .fetch_all(&app_state.pool)
- .await;
- }
- _ => {
- search_attempt = sqlx::query_as!(
- Album,
- "SELECT album.name, album.id,
- artist.name as artist_name, artist.id as artist_id
- FROM album
- INNER JOIN artist ON album.artist_id = artist.id
- ",
- )
- .fetch_all(&app_state.pool)
- .await;
+ app_state
+ .database
+ .select_albums_by_artist(&get_args.artist.clone().unwrap())
+ .await
}
+ _ => app_state.database.select_albums().await,
};
match search_attempt {