added position column to playlist_songs table
This commit is contained in:
parent
9c2cd94955
commit
4d734ef594
@ -8,5 +8,6 @@ CREATE TABLE playlists (
|
|||||||
CREATE TABLE playlist_songs (
|
CREATE TABLE playlist_songs (
|
||||||
playlist_id INTEGER REFERENCES playlists(id) ON DELETE CASCADE NOT NULL,
|
playlist_id INTEGER REFERENCES playlists(id) ON DELETE CASCADE NOT NULL,
|
||||||
song_id INTEGER REFERENCES songs(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)
|
PRIMARY KEY (playlist_id, song_id)
|
||||||
);
|
);
|
@ -122,6 +122,7 @@ pub async fn get_songs(new_playlist_id: Option<i32>) -> Result<Vec<crate::models
|
|||||||
.inner_join(songs)
|
.inner_join(songs)
|
||||||
.filter(playlist_id.eq(other_playlist_id))
|
.filter(playlist_id.eq(other_playlist_id))
|
||||||
.select(songs::all_columns())
|
.select(songs::all_columns())
|
||||||
|
.order_by(position)
|
||||||
.load(db_con)
|
.load(db_con)
|
||||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting songs from playlist: {}", e)))?;
|
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting songs from playlist: {}", e)))?;
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ pub fn PlaylistSong(song: Song, playlist_id: Option<i32>, set_songs: WriteSignal
|
|||||||
|
|
||||||
let delete_song = move |_| {
|
let delete_song = move |_| {
|
||||||
spawn_local(async 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 {
|
if let Err(err) = delete_result {
|
||||||
// Handle the error here, e.g., log it or display to the user
|
// Handle the error here, e.g., log it or display to the user
|
||||||
log!("Error deleting song: {:?}", err);
|
log!("Error deleting song: {:?}", err);
|
||||||
|
@ -11,16 +11,16 @@ pub fn Playlists() -> impl IntoView {
|
|||||||
let (playlists, set_playlists) = create_signal(vec![]);
|
let (playlists, set_playlists) = create_signal(vec![]);
|
||||||
|
|
||||||
create_effect(move |_| {
|
create_effect(move |_| {
|
||||||
|
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
let playlists = get_playlists().await;
|
let playlists2 = get_playlists().await;
|
||||||
if let Err(err) = playlists {
|
if let Err(err) = playlists2 {
|
||||||
// Handle the error here, e.g., log it or display to the user
|
// Handle the error here, e.g., log it or display to the user
|
||||||
log!("Error getting playlists: {:?}", err);
|
log!("Error getting playlists: {:?}", err);
|
||||||
} else {
|
} else {
|
||||||
log!("Playlists: {:?}", playlists);
|
set_playlists.update(|value| *value = playlists2.unwrap());
|
||||||
set_playlists.update(|value| *value = playlists.unwrap());
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
|
@ -26,6 +26,7 @@ diesel::table! {
|
|||||||
playlist_songs (playlist_id, song_id) {
|
playlist_songs (playlist_id, song_id) {
|
||||||
playlist_id -> Int4,
|
playlist_id -> Int4,
|
||||||
song_id -> Int4,
|
song_id -> Int4,
|
||||||
|
position -> Int4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user