Create song #33

Merged
phoenix merged 9 commits from create_song into devel 2025-07-15 00:53:13 +00:00
3 changed files with 45 additions and 29 deletions
Showing only changes of commit efc73518d7 - Show all commits

View File

@@ -1,6 +1,4 @@
pub async fn fetch_next_queue_item(
base_url: &String,
) -> Result<reqwest::Response, reqwest::Error> {
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}");
@@ -131,4 +129,3 @@ pub mod get_coverart_queue {
}
}
}

View File

@@ -94,9 +94,19 @@ async fn some_work(
let user_id = uuid::Uuid::new_v4();
// TODO: Place this somewhere else
let song_type = String::from("flac");
// Err(std::io::Error::other(err.to_string()))
match the_rest::create_song::create(app_base_url, &metadata, &user_id, &song_type).await {
Ok(response) => match response.json::<the_rest::create_song::response::Response>().await {
// Err(std::io::Error::other(err.to_string()))
match the_rest::create_song::create(
app_base_url,
&metadata,
&user_id,
&song_type,
)
.await
{
Ok(response) => match response
.json::<the_rest::create_song::response::Response>()
.await
{
Ok(resp) => {
println!("Response: {resp:?}");
@@ -111,13 +121,9 @@ async fn some_work(
// println!("Response json: {:?}", response.text().await);
Ok(())
}
Err(err) => {
Err(std::io::Error::other(err.to_string()))
}
}
Err(err) => {
Err(std::io::Error::other(err.to_string()))
}
Err(err) => Err(std::io::Error::other(err.to_string())),
},
Err(err) => Err(std::io::Error::other(err.to_string())),
}
}
Err(err) => Err(std::io::Error::other(err.to_string())),
@@ -136,7 +142,15 @@ async fn some_work(
async fn prep_song(
api_url: &String,
song_queue_id: &uuid::Uuid,
) -> Result<(String, String, api::get_metadata_queue::response::Metadata, uuid::Uuid), reqwest::Error> {
) -> Result<
(
String,
String,
api::get_metadata_queue::response::Metadata,
uuid::Uuid,
),
reqwest::Error,
> {
match api::fetch_song_queue_data::get_data(api_url, song_queue_id).await {
Ok(response) => {
// Process data here...

View File

@@ -2,8 +2,13 @@
// TODO: Create song
pub mod create_song {
pub async fn create(base_url: &String, metadata_queue: &crate::api::get_metadata_queue::response::Metadata, user_id: &uuid::Uuid, song_type: &String) -> Result<reqwest::Response, reqwest::Error> {
let payload = serde_json::json!(
pub async fn create(
base_url: &String,
metadata_queue: &crate::api::get_metadata_queue::response::Metadata,
user_id: &uuid::Uuid,
song_type: &String,
) -> Result<reqwest::Response, reqwest::Error> {
let payload = serde_json::json!(
{
"album": &metadata_queue.album,
"album_artist": &metadata_queue.album_artist,
@@ -22,21 +27,21 @@ pub async fn create(base_url: &String, metadata_queue: &crate::api::get_metadata
}
);
let client = reqwest::Client::builder().build()?;
let client = reqwest::Client::builder().build()?;
let url = format!("{base_url}/api/v2/song");
let url = format!("{base_url}/api/v2/song");
let request = client.post(url).json(&payload);
request.send().await
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::song::Song>,
let request = client.post(url).json(&payload);
request.send().await
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::song::Song>,
}
}
}
}
// TODO: Create coverart