Queued song linked to user

This commit is contained in:
kdeng00
2025-08-28 12:59:05 -04:00
parent 9d998938b2
commit 5716046e34
3 changed files with 49 additions and 3 deletions
+11 -1
View File
@@ -430,16 +430,26 @@ impl CommitManager {
match up.queue_song(token, song).await {
Ok(id) => {
println!("Song queued");
queued_song_id = id;
}
Err(err) => {
eprintln!("Error: {err:?}");
return Err(std::io::Error::other(err.to_string()));
}
}
println!("Queued song Id: {queued_song_id:?}");
match up.link_user_to_queued_song(token, &queued_song_id).await {
Ok(_) => {
println!("Queued song linked to user");
}
Err(err) => {
return Err(std::io::Error::other(err.to_string()));
}
}
Ok(())
}
+7
View File
@@ -19,3 +19,10 @@ fn retrieve_url_with_id(api: &models::api::Api, id: &uuid::Uuid) -> String {
url
}
pub async fn auth_header(token: &icarus_models::token::AccessToken) -> (http::HeaderName, http::HeaderValue) {
let auth = reqwest::header::AUTHORIZATION;
let auth_value = http::HeaderValue::from_str(&token.bearer_token()).unwrap();
(auth, auth_value)
}
+31 -2
View File
@@ -84,9 +84,10 @@ impl Upload {
println!("Url: {url:?}");
let mut headers = reqwest::header::HeaderMap::new();
let (auth, auth_val) = syncers::common::auth_header(token).await;
headers.insert(
reqwest::header::AUTHORIZATION,
HeaderValue::from_str(&token.bearer_token()).unwrap(),
auth,
auth_val
);
headers.insert("Accept", HeaderValue::from_str("*/*").unwrap());
headers.insert("Connection", HeaderValue::from_str("keep-alive").unwrap());
@@ -115,6 +116,34 @@ impl Upload {
}
}
pub async fn link_user_to_queued_song(&self, token: &icarus_models::token::AccessToken, queued_song_id: &uuid::Uuid) -> Result<(), reqwest::Error> {
let endpoint = String::from("api/v2/song/queue/link");
let url = format!("{}/{endpoint}", self.api.url);
let mut headers = reqwest::header::HeaderMap::new();
let (auth, auth_val) = syncers::common::auth_header(token).await;
headers.insert(
auth,
auth_val
);
let client = reqwest::Client::builder().build().unwrap();
let payload = serde_json::json!({
"song_queue_id": queued_song_id,
"user_id": token.user_id
});
match client.patch(url).headers(headers).json(&payload).send().await {
Ok(_) => {
Ok(())
}
Err(err) => {
Err(err)
}
}
}
fn init_form(
&self,
song: &icarus_models::song::Song,