API Endpoints for Album Queries
This commit is contained in:
37
src/api/album.rs
Normal file
37
src/api/album.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use leptos::*;
|
||||
use crate::models::Album;
|
||||
use crate::models::Song;
|
||||
use crate::songdata::SongData;
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "ssr")] {
|
||||
use leptos::server_fn::error::NoCustomError;
|
||||
use crate::database::get_db_conn;
|
||||
}
|
||||
}
|
||||
|
||||
#[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_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_list(album: Option<Album>) -> Result<Vec<Song>, ServerFnError> {
|
||||
// songs = get_songs(album)?;
|
||||
|
||||
// let mut song_data_list = Vec::new();
|
||||
// // TODO: NEEDS SONG DATA QUERIES
|
||||
// }
|
@ -1,3 +1,4 @@
|
||||
pub mod history;
|
||||
pub mod profile;
|
||||
pub mod songs;
|
||||
pub mod album;
|
||||
|
Reference in New Issue
Block a user