Link user to queued song (#59)
* Renaming queue_song function * Queued song linked to user * Cleanup and code formatting
This commit was merged in pull request #59.
This commit is contained in:
@@ -36,6 +36,13 @@ enum En {
|
||||
Other,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct UploadSongMembers {
|
||||
pub song: icarus_models::song::Song,
|
||||
pub coverart: icarus_models::coverart::CoverArt,
|
||||
pub token: icarus_models::token::AccessToken,
|
||||
}
|
||||
|
||||
pub fn retrieve_song(
|
||||
album: &icarus_models::album::collection::Album,
|
||||
track: i32,
|
||||
@@ -378,7 +385,13 @@ impl CommitManager {
|
||||
|
||||
cover_art.data = cover_art.to_data().unwrap();
|
||||
|
||||
match self.queue_song(&token, &s).await {
|
||||
let members = UploadSongMembers {
|
||||
song: s,
|
||||
coverart: cover_art,
|
||||
token: token,
|
||||
};
|
||||
|
||||
match self.upload_song_process(&members).await {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
@@ -398,30 +411,34 @@ impl CommitManager {
|
||||
}
|
||||
}
|
||||
|
||||
async fn queue_song(
|
||||
&self,
|
||||
token: &icarus_models::token::AccessToken,
|
||||
song: &icarus_models::song::Song,
|
||||
) -> Result<()> {
|
||||
async fn upload_song_process(&self, data: &UploadSongMembers) -> Result<()> {
|
||||
let mut up = syncers::upload::Upload::default();
|
||||
let host = self.ica_action.retrieve_flag_value(&String::from("-h"));
|
||||
up.set_api(&host);
|
||||
|
||||
let mut queued_song_id = uuid::Uuid::nil();
|
||||
let token = &data.token;
|
||||
let song = &data.song;
|
||||
|
||||
println!("Queueing song");
|
||||
|
||||
match up.queue_song(token, song).await {
|
||||
Ok(id) => {
|
||||
queued_song_id = id;
|
||||
}
|
||||
let queued_song_id = match up.queue_song(token, song).await {
|
||||
Ok(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(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user