From 4d734ef594e1efbcaaf5edfc9eaab57ea2ce7071 Mon Sep 17 00:00:00 2001 From: dannyzou18 Date: Sat, 4 May 2024 19:43:43 -0400 Subject: [PATCH] added position column to playlist_songs table --- .../2024-04-13-024749_create_playlists_table/up.sql | 1 + src/api/playlists.rs | 1 + src/components/playlist.rs | 2 +- src/components/playlists.rs | 10 +++++----- src/schema.rs | 1 + 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/migrations/2024-04-13-024749_create_playlists_table/up.sql b/migrations/2024-04-13-024749_create_playlists_table/up.sql index affcfdb..225305e 100644 --- a/migrations/2024-04-13-024749_create_playlists_table/up.sql +++ b/migrations/2024-04-13-024749_create_playlists_table/up.sql @@ -8,5 +8,6 @@ CREATE TABLE playlists ( CREATE TABLE playlist_songs ( playlist_id INTEGER REFERENCES playlists(id) ON DELETE CASCADE NOT NULL, song_id INTEGER REFERENCES songs(id) ON DELETE CASCADE NOT NULL, + position INTEGER NOT NULL, PRIMARY KEY (playlist_id, song_id) ); \ No newline at end of file diff --git a/src/api/playlists.rs b/src/api/playlists.rs index 3d18cd8..cd645e7 100644 --- a/src/api/playlists.rs +++ b/src/api/playlists.rs @@ -122,6 +122,7 @@ pub async fn get_songs(new_playlist_id: Option) -> Result::ServerError(format!("Error getting songs from playlist: {}", e)))?; diff --git a/src/components/playlist.rs b/src/components/playlist.rs index d9df472..4ea6d1d 100644 --- a/src/components/playlist.rs +++ b/src/components/playlist.rs @@ -105,7 +105,7 @@ pub fn PlaylistSong(song: Song, playlist_id: Option, set_songs: WriteSignal let delete_song = move |_| { spawn_local(async move { - let delete_result = remove_song(song.id.clone(), playlist_id).await; + let delete_result = remove_song(playlist_id,song.id.clone()).await; if let Err(err) = delete_result { // Handle the error here, e.g., log it or display to the user log!("Error deleting song: {:?}", err); diff --git a/src/components/playlists.rs b/src/components/playlists.rs index 9b4849f..3df2966 100644 --- a/src/components/playlists.rs +++ b/src/components/playlists.rs @@ -11,16 +11,16 @@ pub fn Playlists() -> impl IntoView { let (playlists, set_playlists) = create_signal(vec![]); create_effect(move |_| { + spawn_local(async move { - let playlists = get_playlists().await; - if let Err(err) = playlists { + let playlists2 = get_playlists().await; + if let Err(err) = playlists2 { // Handle the error here, e.g., log it or display to the user log!("Error getting playlists: {:?}", err); } else { - log!("Playlists: {:?}", playlists); - set_playlists.update(|value| *value = playlists.unwrap()); + set_playlists.update(|value| *value = playlists2.unwrap()); } - }) + }); }); view! { diff --git a/src/schema.rs b/src/schema.rs index f532d10..e0f6c1f 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -26,6 +26,7 @@ diesel::table! { playlist_songs (playlist_id, song_id) { playlist_id -> Int4, song_id -> Int4, + position -> Int4, } }