Code formatting

This commit is contained in:
2025-10-13 21:54:52 -04:00
parent c64ecd8a54
commit f174239c2e
2 changed files with 135 additions and 11 deletions

View File

@@ -1,4 +1,3 @@
pub mod fetch_next_queue_item { pub mod fetch_next_queue_item {
pub async fn fetch_next_queue_item( pub async fn fetch_next_queue_item(
@@ -15,7 +14,6 @@ pub mod fetch_next_queue_item {
pub mod response { pub mod response {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct QueueItem { pub struct QueueItem {
pub id: uuid::Uuid, pub id: uuid::Uuid,
@@ -229,3 +227,130 @@ pub mod update_queued_song {
} }
} }
} }
pub mod create_song {
pub async fn create(
app: &crate::config::App,
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,
"artist": &metadata_queue.artist,
"disc": metadata_queue.disc,
"disc_count": metadata_queue.disc_count,
"duration": metadata_queue.duration,
"genre": &metadata_queue.genre,
"title": &metadata_queue.title,
"track": metadata_queue.track,
"track_count": metadata_queue.track_count,
"date": metadata_queue.year.to_string(),
"audio_type": &song_type,
"user_id": &user_id,
"song_queue_id": &metadata_queue.song_queue_id,
}
);
let client = reqwest::Client::builder().build()?;
let url = format!("{}/api/v2/song", app.uri);
let (key, header) = crate::api::auth_header(app).await;
let request = client.post(url).json(&payload).header(key, header);
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>,
}
}
}
pub mod create_coverart {
pub async fn create(
app: &crate::config::App,
song_id: &uuid::Uuid,
coverart_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{}/api/v2/coverart", app.uri);
let payload = get_payload(song_id, coverart_queue_id);
let (key, header) = crate::api::auth_header(app).await;
let request = client.post(url).json(&payload).header(key, header);
request.send().await
}
fn get_payload(song_id: &uuid::Uuid, coverart_queue_id: &uuid::Uuid) -> serde_json::Value {
serde_json::json!({
"song_id": &song_id,
"coverart_queue_id": &coverart_queue_id,
})
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::coverart::CoverArt>,
}
}
}
pub mod wipe_data {
pub mod song_queue {
pub async fn wipe_data(
app: &crate::config::App,
song_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{}/api/v2/song/queue/data/wipe", app.uri);
let payload = serde_json::json!({
"song_queue_id": song_queue_id
});
let (key, header) = crate::api::auth_header(app).await;
let request = client.patch(url).json(&payload).header(key, header);
request.send().await
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<uuid::Uuid>,
}
}
}
pub mod coverart_queue {
pub async fn wipe_data(
app: &crate::config::App,
coverart_queue_id: &uuid::Uuid,
) -> Result<reqwest::Response, reqwest::Error> {
let client = reqwest::Client::builder().build()?;
let url = format!("{}/api/v2/coverart/queue/data/wipe", app.uri);
let payload = serde_json::json!({
"coverart_queue_id": coverart_queue_id
});
let (key, header) = crate::api::auth_header(app).await;
let request = client.patch(url).json(&payload).header(key, header);
request.send().await
}
pub mod response {
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Response {
pub message: String,
pub data: Vec<uuid::Uuid>,
}
}
}
}

View File

@@ -1,6 +1,5 @@
pub mod api; pub mod api;
pub mod config; pub mod config;
pub mod the_rest;
pub mod util; pub mod util;
pub const SECONDS_TO_SLEEP: u64 = 5; pub const SECONDS_TO_SLEEP: u64 = 5;
@@ -171,15 +170,15 @@ async fn wipe_data_from_queues(
song_queue_id: &uuid::Uuid, song_queue_id: &uuid::Uuid,
coverart_queue_id: &uuid::Uuid, coverart_queue_id: &uuid::Uuid,
) -> Result<(), std::io::Error> { ) -> Result<(), std::io::Error> {
match the_rest::wipe_data::song_queue::wipe_data(app, song_queue_id).await { match api::wipe_data::song_queue::wipe_data(app, song_queue_id).await {
Ok(response) => match response Ok(response) => match response
.json::<the_rest::wipe_data::song_queue::response::Response>() .json::<api::wipe_data::song_queue::response::Response>()
.await .await
{ {
Ok(_resp) => { Ok(_resp) => {
match the_rest::wipe_data::coverart_queue::wipe_data(app, coverart_queue_id).await { match api::wipe_data::coverart_queue::wipe_data(app, coverart_queue_id).await {
Ok(inner_response) => match inner_response Ok(inner_response) => match inner_response
.json::<the_rest::wipe_data::coverart_queue::response::Response>() .json::<api::wipe_data::coverart_queue::response::Response>()
.await .await
{ {
Ok(_inner_resp) => { Ok(_inner_resp) => {
@@ -278,13 +277,13 @@ async fn some_work(
// TODO: Place this somewhere else // TODO: Place this somewhere else
let song_type = String::from("flac"); let song_type = String::from("flac");
match the_rest::create_song::create( match api::create_song::create(
app, &metadata, user_id, &song_type, app, &metadata, user_id, &song_type,
) )
.await .await
{ {
Ok(response) => match response Ok(response) => match response
.json::<the_rest::create_song::response::Response>() .json::<api::create_song::response::Response>()
.await .await
{ {
Ok(resp) => { Ok(resp) => {
@@ -294,8 +293,8 @@ async fn some_work(
song.directory = song_directory; song.directory = song_directory;
song.filename = song_filename; song.filename = song_filename;
match the_rest::create_coverart::create(app, &song.id, &coverart_queue_id).await { match api::create_coverart::create(app, &song.id, &coverart_queue_id).await {
Ok(response) => match response.json::<the_rest::create_coverart::response::Response>().await { Ok(response) => match response.json::<api::create_coverart::response::Response>().await {
Ok(resp) => { Ok(resp) => {
println!("CoverArt sent and successfully parsed response"); println!("CoverArt sent and successfully parsed response");
println!("json: {resp:?}"); println!("json: {resp:?}");