Able to fetch next song queue item

This commit is contained in:
2025-06-10 18:37:55 -04:00
parent b3dca9bd1a
commit 4c56b48aef

View File

@@ -5,7 +5,6 @@
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::new();
let app_base_url = get_icarus_url().await;
loop {
@@ -14,12 +13,25 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// TODO: Update the api/v2/song/queue/next endpoint to only retrieve queued song that is
// ready to be processed. Make necessary changes to other endpoints
let api_url = format!("{}/api/v2/song/queue/next", app_base_url);
// let api_url = format!("{}/api/v2/song/queue/next", app_base_url);
match client.get(api_url).send().await {
// match client.get(api_url).send().await {
match api::fetch_next_queue_item(&app_base_url).await {
Ok(response) => {
let body = response.text().await?;
println!("API response: {}", body);
// let body = response.text().await?;
// println!("API response: {}", body);
match response.json::<responses::fetch_next_queue_item::SongQueueItem>().await {
Ok(song_queue_item) => {
if !song_queue_item.data.is_empty() {
println!("Song queue item: {:?}", song_queue_item);
} else {
println!("No data to fetch");
}
}
Err(err) => {
eprintln!("Error: {:?}", err);
}
}
// Process data here...
// TODO: Parse the response body to a struct
@@ -43,6 +55,37 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Ok(())
}
mod responses {
pub mod fetch_next_queue_item {
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct QueueItem {
pub id: uuid::Uuid,
pub filename: String,
pub status: String,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct SongQueueItem {
pub message: String,
pub data: Vec<QueueItem>,
}
}
}
mod api {
pub async fn fetch_next_queue_item(base_url: &String) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::new();
let fetch_endpoint = String::from("api/v2/song/queue/next");
let api_url = format!("{}/{}", base_url, fetch_endpoint);
let resp = client.get(api_url).send().await;
// Ok(resp)
resp
}
}
async fn get_icarus_url() -> String {
dotenvy::dotenv().ok();
std::env::var("ICARUS_BASE_API_URL").expect("Could not find url")