Add playlist and favorites commands, update sidebar
Backend: - Add playlist.rs commands: get_user_playlists, get_playlist, search_playlists - Add favorites.rs commands: get_favorites, add_favorite, remove_favorite - Add API client methods: search_playlists, add_favorite, remove_favorite Frontend: - Remove Radio and New from sidebar (no API support) - Sidebar now loads and displays user playlists dynamically - Add playlist and favorites views (placeholder for now) - Pass selectedPlaylistId and onPlaylistSelect to Sidebar
This commit is contained in:
1 parent
dd2600feaa
commit
bda4ea5b76
7 files changed
+276
-50
No files matched your search
@@ -424,6 +424,68 @@ impl QobuzClient {
|
||||
|
||||
Ok(serde_json::from_value(playlists.clone())?)
|
||||
}
|
||||
|
||||
/// Search playlists
|
||||
pub async fn search_playlists(&self, query: &str, limit: u32) -> Result<SearchResultsPage<Playlist>> {
|
||||
let url = endpoints::build_url(paths::PLAYLIST_SEARCH);
|
||||
let response: Value = self
|
||||
.http
|
||||
.get(&url)
|
||||
.header("X-App-Id", self.app_id().await?)
|
||||
.query(&[("query", query), ("limit", &limit.to_string())])
|
||||
.send()
|
||||
.await?
|
||||
.json()
|
||||
.await?;
|
||||
|
||||
let playlists = response
|
||||
.get("playlists")
|
||||
.ok_or_else(|| ApiError::ApiResponse("No playlists in response".to_string()))?;
|
||||
|
||||
Ok(serde_json::from_value(playlists.clone())?)
|
||||
}
|
||||
|
||||
/// Add item to favorites
|
||||
pub async fn add_favorite(&self, fav_type: &str, item_id: &str) -> Result<()> {
|
||||
let url = endpoints::build_url(paths::FAVORITE_CREATE);
|
||||
let type_key = format!("{}_ids", fav_type); // album_ids, track_ids, artist_ids
|
||||
|
||||
let response = self
|
||||
.http
|
||||
.get(&url)
|
||||
.header("X-App-Id", self.app_id().await?)
|
||||
.header("X-User-Auth-Token", self.auth_token().await?)
|
||||
.query(&[(&type_key, item_id)])
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if response.status().is_success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ApiError::ApiResponse(format!("Failed to add favorite: {}", response.status())))
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove item from favorites
|
||||
pub async fn remove_favorite(&self, fav_type: &str, item_id: &str) -> Result<()> {
|
||||
let url = endpoints::build_url(paths::FAVORITE_DELETE);
|
||||
let type_key = format!("{}_ids", fav_type);
|
||||
|
||||
let response = self
|
||||
.http
|
||||
.get(&url)
|
||||
.header("X-App-Id", self.app_id().await?)
|
||||
.header("X-User-Auth-Token", self.auth_token().await?)
|
||||
.query(&[(&type_key, item_id)])
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
if response.status().is_success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ApiError::ApiResponse(format!("Failed to remove favorite: {}", response.status())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for QobuzClient {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
//! Favorites-related Tauri commands
|
||||
|
||||
use serde_json::Value;
|
||||
use tauri::State;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::api::client::QobuzClient;
|
||||
|
||||
/// Get user's favorites
|
||||
/// fav_type can be: "albums", "tracks", or "artists"
|
||||
#[tauri::command]
|
||||
pub async fn get_favorites(
|
||||
fav_type: String,
|
||||
limit: Option<u32>,
|
||||
offset: Option<u32>,
|
||||
client: State<'_, std::sync::Arc<Mutex<QobuzClient>>>,
|
||||
) -> Result<Value, String> {
|
||||
log::info!("Command: get_favorites type={} limit={:?} offset={:?}", fav_type, limit, offset);
|
||||
|
||||
let client = client.lock().await;
|
||||
client
|
||||
.get_favorites(&fav_type, limit.unwrap_or(50), offset.unwrap_or(0))
|
||||
.await
|
||||
.map_err(|e| format!("Failed to get favorites: {}", e))
|
||||
}
|
||||
|
||||
/// Add item to favorites
|
||||
/// fav_type can be: "album", "track", or "artist"
|
||||
#[tauri::command]
|
||||
pub async fn add_favorite(
|
||||
fav_type: String,
|
||||
item_id: String,
|
||||
client: State<'_, std::sync::Arc<Mutex<QobuzClient>>>,
|
||||
) -> Result<(), String> {
|
||||
log::info!("Command: add_favorite type={} id={}", fav_type, item_id);
|
||||
|
||||
let client = client.lock().await;
|
||||
client
|
||||
.add_favorite(&fav_type, &item_id)
|
||||
.await
|
||||
.map_err(|e| format!("Failed to add favorite: {}", e))
|
||||
}
|
||||
|
||||
/// Remove item from favorites
|
||||
/// fav_type can be: "album", "track", or "artist"
|
||||
#[tauri::command]
|
||||
pub async fn remove_favorite(
|
||||
fav_type: String,
|
||||
item_id: String,
|
||||
client: State<'_, std::sync::Arc<Mutex<QobuzClient>>>,
|
||||
) -> Result<(), String> {
|
||||
log::info!("Command: remove_favorite type={} id={}", fav_type, item_id);
|
||||
|
||||
let client = client.lock().await;
|
||||
client
|
||||
.remove_favorite(&fav_type, &item_id)
|
||||
.await
|
||||
.map_err(|e| format!("Failed to remove favorite: {}", e))
|
||||
}
|
||||
@@ -3,11 +3,15 @@
|
||||
//! Exposes backend functionality to the frontend via IPC
|
||||
|
||||
pub mod auth;
|
||||
pub mod favorites;
|
||||
pub mod playback;
|
||||
pub mod playlist;
|
||||
pub mod queue;
|
||||
pub mod search;
|
||||
|
||||
pub use auth::*;
|
||||
pub use favorites::*;
|
||||
pub use playback::*;
|
||||
pub use playlist::*;
|
||||
pub use queue::*;
|
||||
pub use search::*;
|
||||
@@ -0,0 +1,52 @@
|
||||
//! Playlist-related Tauri commands
|
||||
|
||||
use tauri::State;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::api::client::QobuzClient;
|
||||
use crate::api::models::{Playlist, SearchResultsPage};
|
||||
|
||||
/// Get user's playlists
|
||||
#[tauri::command]
|
||||
pub async fn get_user_playlists(
|
||||
client: State<'_, std::sync::Arc<Mutex<QobuzClient>>>,
|
||||
) -> Result<Vec<Playlist>, String> {
|
||||
log::info!("Command: get_user_playlists");
|
||||
|
||||
let client = client.lock().await;
|
||||
client
|
||||
.get_user_playlists()
|
||||
.await
|
||||
.map_err(|e| format!("Failed to get user playlists: {}", e))
|
||||
}
|
||||
|
||||
/// Get a specific playlist by ID
|
||||
#[tauri::command]
|
||||
pub async fn get_playlist(
|
||||
playlist_id: u64,
|
||||
client: State<'_, std::sync::Arc<Mutex<QobuzClient>>>,
|
||||
) -> Result<Playlist, String> {
|
||||
log::info!("Command: get_playlist {}", playlist_id);
|
||||
|
||||
let client = client.lock().await;
|
||||
client
|
||||
.get_playlist(playlist_id)
|
||||
.await
|
||||
.map_err(|e| format!("Failed to get playlist: {}", e))
|
||||
}
|
||||
|
||||
/// Search playlists
|
||||
#[tauri::command]
|
||||
pub async fn search_playlists(
|
||||
query: String,
|
||||
limit: Option<u32>,
|
||||
client: State<'_, std::sync::Arc<Mutex<QobuzClient>>>,
|
||||
) -> Result<SearchResultsPage<Playlist>, String> {
|
||||
log::info!("Command: search_playlists \"{}\"", query);
|
||||
|
||||
let client = client.lock().await;
|
||||
client
|
||||
.search_playlists(&query, limit.unwrap_or(20))
|
||||
.await
|
||||
.map_err(|e| format!("Failed to search playlists: {}", e))
|
||||
}
|
||||
@@ -116,6 +116,14 @@ pub fn run() {
|
||||
commands::set_repeat,
|
||||
commands::get_repeat,
|
||||
commands::get_queue_state,
|
||||
// Playlist commands
|
||||
commands::get_user_playlists,
|
||||
commands::get_playlist,
|
||||
commands::search_playlists,
|
||||
// Favorites commands
|
||||
commands::get_favorites,
|
||||
commands::add_favorite,
|
||||
commands::remove_favorite,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Reference in new issue
Block a user