API Endpoints for Album Queries

This commit is contained in:
2024-10-25 21:23:21 +00:00
parent df01bafbd1
commit fe1b76e6e4
6 changed files with 65 additions and 20 deletions

37
src/api/album.rs Normal file
View 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
// }

View File

@ -1,3 +1,4 @@
pub mod history;
pub mod profile;
pub mod songs;
pub mod album;