Working Albums Page (BETA)
This commit is contained in:
parent
7a1ffaad47
commit
568f6ada0e
@ -13,25 +13,20 @@ cfg_if! {
|
||||
}
|
||||
}
|
||||
|
||||
// #[server(endpoint = "album/get")]
|
||||
// pub async fn get_album(id: Option<i32>) -> Result<Album, ServerFnError> {
|
||||
// let db_con = &mut get_db_conn();
|
||||
// let album = Album::get_album(id,db_con)
|
||||
// .map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting album: {}", e)))?;
|
||||
// Ok(album)
|
||||
// }
|
||||
#[server(endpoint = "album/get")]
|
||||
pub async fn get_album(id: i32) -> Result<Album, ServerFnError> {
|
||||
let db_con = &mut get_db_conn();
|
||||
let album = Album::get_album(id,db_con)
|
||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting album: {}", e)))?;
|
||||
Ok(album)
|
||||
}
|
||||
|
||||
// #[server(endpoint = "album/get_songs")]
|
||||
// pub async fn get_songs(album: Option<Album>) -> Result<Vec<Song>, ServerFnError> {
|
||||
// let db_con = &mut get_db_conn();
|
||||
// let songs = album.get_songs(db_con)
|
||||
// .map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting album: {}", e)))?;
|
||||
// Ok(songs)
|
||||
// }
|
||||
|
||||
// #[server(endpoint = "album/get_song_list")]
|
||||
// pub async fn get_song_data(album: Option<Album>) -> Result<Vec<Song>, ServerFnError> {
|
||||
// let user = get_user().await?;
|
||||
// let db_con = &mut get_db_conn();
|
||||
// // TODO: NEEDS SONG DATA QUERIES
|
||||
// }
|
||||
#[server(endpoint = "album/get_songs")]
|
||||
pub async fn get_songs(id: i32) -> Result<Vec<SongData>, ServerFnError> {
|
||||
let user = get_user().await?;
|
||||
let db_con = &mut get_db_conn();
|
||||
// TODO: NEEDS SONG DATA QUERIES
|
||||
let songdata = Album::get_song_data(id,user.id.unwrap(),db_con)
|
||||
.map_err(|e| ServerFnError::<NoCustomError>::ServerError(format!("Error getting song data: {}", e)))?;
|
||||
Ok(songdata)
|
||||
}
|
@ -43,7 +43,7 @@ pub fn App() -> impl IntoView {
|
||||
<Route path="" view=Dashboard />
|
||||
<Route path="dashboard" view=Dashboard />
|
||||
<Route path="search" view=Search />
|
||||
//<Route path="album/:id" view=AlbumPage />
|
||||
<Route path="album/:id" view=AlbumPage />
|
||||
</Route>
|
||||
<Route path="/login" view=Login />
|
||||
<Route path="/signup" view=Signup />
|
||||
|
@ -540,7 +540,7 @@ impl Album {
|
||||
/// * `Result<Album, Box<dyn Error>>` - A result indicating success with the desired album, or an error
|
||||
///
|
||||
#[cfg(feature = "ssr")]
|
||||
pub fn get_album(album_id: i32, user_id: i32, conn: &mut PgPooledConn) -> Result<Album, Box<dyn Error>> {
|
||||
pub fn get_album(album_id: i32, conn: &mut PgPooledConn) -> Result<Album, Box<dyn Error>> {
|
||||
use crate::schema::albums::dsl::*;
|
||||
use crate::database::get_db_conn;
|
||||
|
||||
|
@ -3,6 +3,7 @@ use leptos::*;
|
||||
use leptos_router::*;
|
||||
use crate::models::*;
|
||||
use crate::components::song_list::*;
|
||||
use crate::api::album::*;
|
||||
|
||||
|
||||
#[derive(Params, PartialEq)]
|
||||
@ -10,7 +11,6 @@ struct AlbumParams {
|
||||
id: i32
|
||||
}
|
||||
|
||||
/*
|
||||
#[component]
|
||||
pub fn AlbumPage() -> impl IntoView {
|
||||
let params = use_params::<AlbumParams>();
|
||||
@ -26,8 +26,8 @@ pub fn AlbumPage() -> impl IntoView {
|
||||
id,
|
||||
|value| async move {
|
||||
match value {
|
||||
Ok(v) => {get_album(v).await},
|
||||
Err(e) => {Err(ServerFnError::Request("Invalid album!".into()))},
|
||||
Ok(v) => {get_songs(v).await},
|
||||
Err(e) => {Err(ServerFnError::Request(format!("Error getting song data: {}", e).into()))},
|
||||
}
|
||||
},
|
||||
);
|
||||
@ -40,7 +40,7 @@ pub fn AlbumPage() -> impl IntoView {
|
||||
song_list.with( |song_list| {
|
||||
match song_list {
|
||||
Some(Ok(s)) => {
|
||||
view! { <SongList songs=s.clone().into()/> }.into_view()
|
||||
view! { <SongList songs=(*s).clone().into()/> }.into_view()
|
||||
},
|
||||
Some(Err(e)) => {
|
||||
view! { <div>"Error loading albums: :e"</div> }.into_view()
|
||||
@ -52,4 +52,4 @@ pub fn AlbumPage() -> impl IntoView {
|
||||
</Suspense>
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user