Updating name (#253)
soaricarus_api CI / Check (push) Successful in 3m21s
soaricarus_api CI / Test Suite (push) Successful in 4m25s
soaricarus_api CI / Rustfmt (push) Successful in 3m8s
soaricarus_api CI / Clippy (push) Successful in 3m56s
soaricarus_api CI / build (push) Successful in 3m3s
soaricarus_api CI / Check (push) Successful in 3m21s
soaricarus_api CI / Test Suite (push) Successful in 4m25s
soaricarus_api CI / Rustfmt (push) Successful in 3m8s
soaricarus_api CI / Clippy (push) Successful in 3m56s
soaricarus_api CI / build (push) Successful in 3m3s
Reviewed-on: #253
This commit was merged in pull request #253.
This commit is contained in:
+3
-3
@@ -36,11 +36,11 @@ pub async fn auth<B>(
|
||||
(StatusCode::UNAUTHORIZED, Json(json_error))
|
||||
})?;
|
||||
|
||||
let secret_key = icarus_envy::environment::get_secret_main_key().value;
|
||||
let secret_key = sienvy::environment::get_secret_main_key().value;
|
||||
|
||||
let mut validation = Validation::new(jsonwebtoken::Algorithm::HS256);
|
||||
validation.set_audience(&["icarus"]); // Must match exactly what's in the token
|
||||
let _claims = decode::<icarus_models::token::UserClaims>(
|
||||
validation.set_audience(&["soaricarus"]);
|
||||
let _claims = decode::<simodels::token::UserClaims>(
|
||||
&token,
|
||||
&DecodingKey::from_secret(secret_key.as_ref()),
|
||||
&validation,
|
||||
|
||||
+23
-26
@@ -20,7 +20,7 @@ pub mod response {
|
||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<icarus_models::coverart::CoverArt>,
|
||||
pub data: Vec<simodels::coverart::CoverArt>,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ pub mod response {
|
||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<icarus_models::coverart::CoverArt>,
|
||||
pub data: Vec<simodels::coverart::CoverArt>,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,21 +68,21 @@ pub mod endpoint {
|
||||
let song_id = payload.song_id;
|
||||
match crate::repo::song::get_song(&pool, &song_id).await {
|
||||
Ok(song) => {
|
||||
let directory = icarus_envy::environment::get_root_directory().value;
|
||||
let directory = sienvy::environment::get_root_directory().value;
|
||||
let file_type =
|
||||
icarus_meta::detection::coverart::file_type_from_data(&data).unwrap();
|
||||
simeta::detection::coverart::file_type_from_data(&data).unwrap();
|
||||
let coverart_type = if file_type.file_type
|
||||
== icarus_meta::detection::coverart::constants::JPEG_TYPE
|
||||
== simeta::detection::coverart::constants::JPEG_TYPE
|
||||
{
|
||||
icarus_models::types::CoverArtType::JpegExtension
|
||||
simodels::types::CoverArtType::JpegExtension
|
||||
} else if file_type.file_type
|
||||
== icarus_meta::detection::coverart::constants::JPG_TYPE
|
||||
== simeta::detection::coverart::constants::JPG_TYPE
|
||||
{
|
||||
icarus_models::types::CoverArtType::JpgExtension
|
||||
simodels::types::CoverArtType::JpgExtension
|
||||
} else if file_type.file_type
|
||||
== icarus_meta::detection::coverart::constants::PNG_TYPE
|
||||
== simeta::detection::coverart::constants::PNG_TYPE
|
||||
{
|
||||
icarus_models::types::CoverArtType::PngExtension
|
||||
simodels::types::CoverArtType::PngExtension
|
||||
} else {
|
||||
response.message = String::from("Invalid CoverArt type");
|
||||
return (
|
||||
@@ -91,13 +91,11 @@ pub mod endpoint {
|
||||
);
|
||||
};
|
||||
let filename =
|
||||
icarus_models::coverart::generate_filename(coverart_type, true)
|
||||
.unwrap();
|
||||
simodels::coverart::generate_filename(coverart_type, true).unwrap();
|
||||
|
||||
let mut coverart =
|
||||
icarus_models::coverart::init::init_coverart_dir_and_filename(
|
||||
&directory, &filename,
|
||||
);
|
||||
let mut coverart = simodels::coverart::init::init_coverart_dir_and_filename(
|
||||
&directory, &filename,
|
||||
);
|
||||
coverart.title = song.album.clone();
|
||||
coverart.file_type = file_type.file_type;
|
||||
coverart.data = data;
|
||||
@@ -200,23 +198,23 @@ pub mod endpoint {
|
||||
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
||||
) -> (axum::http::StatusCode, axum::response::Response) {
|
||||
match repo::coverart::get_coverart(&pool, &id).await {
|
||||
Ok(coverart) => match icarus_models::coverart::io::to_data(&coverart) {
|
||||
Ok(coverart) => match simodels::coverart::io::to_data(&coverart) {
|
||||
Ok(data) => {
|
||||
let (file_type, img_type) =
|
||||
match icarus_meta::detection::coverart::file_type_from_data(&data) {
|
||||
match simeta::detection::coverart::file_type_from_data(&data) {
|
||||
Ok(file_type) => {
|
||||
if file_type.file_type
|
||||
== icarus_meta::detection::coverart::constants::JPEG_TYPE
|
||||
== simeta::detection::coverart::constants::JPEG_TYPE
|
||||
{
|
||||
(file_type, icarus_models::types::CoverArtType::JpegExtension)
|
||||
(file_type, simodels::types::CoverArtType::JpegExtension)
|
||||
} else if file_type.file_type
|
||||
== icarus_meta::detection::coverart::constants::JPG_TYPE
|
||||
== simeta::detection::coverart::constants::JPG_TYPE
|
||||
{
|
||||
(file_type, icarus_models::types::CoverArtType::JpgExtension)
|
||||
(file_type, simodels::types::CoverArtType::JpgExtension)
|
||||
} else if file_type.file_type
|
||||
== icarus_meta::detection::coverart::constants::PNG_TYPE
|
||||
== simeta::detection::coverart::constants::PNG_TYPE
|
||||
{
|
||||
(file_type, icarus_models::types::CoverArtType::PngExtension)
|
||||
(file_type, simodels::types::CoverArtType::PngExtension)
|
||||
} else {
|
||||
return (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
@@ -235,8 +233,7 @@ pub mod endpoint {
|
||||
let bytes = axum::body::Bytes::from(data);
|
||||
let mut response = bytes.into_response();
|
||||
let headers = response.headers_mut();
|
||||
let filename =
|
||||
icarus_models::coverart::generate_filename(img_type, true).unwrap();
|
||||
let filename = simodels::coverart::generate_filename(img_type, true).unwrap();
|
||||
headers.insert(
|
||||
axum::http::header::CONTENT_TYPE,
|
||||
file_type.mime.parse().unwrap(),
|
||||
|
||||
@@ -102,9 +102,9 @@ pub mod response {
|
||||
mod helper {
|
||||
pub fn is_coverart_file_type_valid(file_type: &String) -> bool {
|
||||
let valid_file_types = vec![
|
||||
String::from(icarus_meta::detection::coverart::constants::JPEG_TYPE),
|
||||
String::from(icarus_meta::detection::coverart::constants::JPG_TYPE),
|
||||
String::from(icarus_meta::detection::coverart::constants::PNG_TYPE),
|
||||
String::from(simeta::detection::coverart::constants::JPEG_TYPE),
|
||||
String::from(simeta::detection::coverart::constants::JPG_TYPE),
|
||||
String::from(simeta::detection::coverart::constants::PNG_TYPE),
|
||||
];
|
||||
|
||||
for valid_file_type in valid_file_types {
|
||||
@@ -150,18 +150,17 @@ pub mod endpoint {
|
||||
let content_type = field.content_type().unwrap().to_string();
|
||||
let data = field.bytes().await.unwrap();
|
||||
let raw_data = data.to_vec();
|
||||
let file_type =
|
||||
match icarus_meta::detection::coverart::file_type_from_data(&raw_data) {
|
||||
Ok(file_type) => file_type,
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
response.message = err.to_string();
|
||||
return (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
);
|
||||
}
|
||||
};
|
||||
let file_type = match simeta::detection::coverart::file_type_from_data(&raw_data) {
|
||||
Ok(file_type) => file_type,
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
response.message = err.to_string();
|
||||
return (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
if !super::helper::is_coverart_file_type_valid(&file_type.file_type) {
|
||||
response.message = format!("CoverArt file type not supported: {file_type:?}");
|
||||
@@ -318,8 +317,7 @@ pub mod endpoint {
|
||||
) -> (axum::http::StatusCode, axum::response::Response) {
|
||||
match repo::coverart::get_coverart_queue_data_with_id(&pool, &id).await {
|
||||
Ok(data) => {
|
||||
let file_type =
|
||||
icarus_meta::detection::coverart::file_type_from_data(&data).unwrap();
|
||||
let file_type = simeta::detection::coverart::file_type_from_data(&data).unwrap();
|
||||
let bytes = axum::body::Bytes::from(data);
|
||||
let mut response = bytes.into_response();
|
||||
let headers = response.headers_mut();
|
||||
@@ -329,25 +327,20 @@ pub mod endpoint {
|
||||
);
|
||||
|
||||
let coverart_type = if file_type.file_type
|
||||
== icarus_meta::detection::coverart::constants::JPEG_TYPE
|
||||
== simeta::detection::coverart::constants::JPEG_TYPE
|
||||
{
|
||||
icarus_models::types::CoverArtType::JpegExtension
|
||||
} else if file_type.file_type
|
||||
== icarus_meta::detection::coverart::constants::JPG_TYPE
|
||||
{
|
||||
icarus_models::types::CoverArtType::JpgExtension
|
||||
} else if file_type.file_type
|
||||
== icarus_meta::detection::coverart::constants::PNG_TYPE
|
||||
{
|
||||
icarus_models::types::CoverArtType::PngExtension
|
||||
simodels::types::CoverArtType::JpegExtension
|
||||
} else if file_type.file_type == simeta::detection::coverart::constants::JPG_TYPE {
|
||||
simodels::types::CoverArtType::JpgExtension
|
||||
} else if file_type.file_type == simeta::detection::coverart::constants::PNG_TYPE {
|
||||
simodels::types::CoverArtType::PngExtension
|
||||
} else {
|
||||
return (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::response::Response::default(),
|
||||
);
|
||||
};
|
||||
let filename =
|
||||
icarus_models::coverart::generate_filename(coverart_type, true).unwrap();
|
||||
let filename = simodels::coverart::generate_filename(coverart_type, true).unwrap();
|
||||
headers.insert(
|
||||
axum::http::header::CONTENT_DISPOSITION,
|
||||
format!("attachment; filename=\"{filename}\"")
|
||||
|
||||
@@ -97,9 +97,9 @@ pub mod response {
|
||||
}
|
||||
|
||||
pub async fn is_song_valid(data: &[u8]) -> Result<bool, std::io::Error> {
|
||||
match icarus_meta::detection::song::file_type_from_data(data) {
|
||||
match simeta::detection::song::file_type_from_data(data) {
|
||||
Ok(file_type) => {
|
||||
if file_type.file_type == icarus_meta::detection::song::constants::FLAC_TYPE {
|
||||
if file_type.file_type == simeta::detection::song::constants::FLAC_TYPE {
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
|
||||
+11
-13
@@ -36,8 +36,8 @@ pub mod request {
|
||||
|| !self.song_queue_id.is_nil()
|
||||
}
|
||||
|
||||
pub fn to_song(&self) -> icarus_models::song::Song {
|
||||
icarus_models::song::Song {
|
||||
pub fn to_song(&self) -> simodels::song::Song {
|
||||
simodels::song::Song {
|
||||
id: uuid::Uuid::nil(),
|
||||
title: self.title.clone(),
|
||||
artist: self.artist.clone(),
|
||||
@@ -71,7 +71,7 @@ pub mod response {
|
||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<icarus_models::song::Song>,
|
||||
pub data: Vec<simodels::song::Song>,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,15 +79,15 @@ pub mod response {
|
||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<icarus_models::song::Song>,
|
||||
pub data: Vec<simodels::song::Song>,
|
||||
}
|
||||
}
|
||||
|
||||
pub mod delete_song {
|
||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||
pub struct SongAndCoverArt {
|
||||
pub song: icarus_models::song::Song,
|
||||
pub coverart: icarus_models::coverart::CoverArt,
|
||||
pub song: simodels::song::Song,
|
||||
pub coverart: simodels::coverart::CoverArt,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
|
||||
@@ -134,12 +134,10 @@ pub mod endpoint {
|
||||
|
||||
if payload.is_valid() {
|
||||
let mut song = payload.to_song();
|
||||
song.filename = icarus_models::song::generate_filename(
|
||||
icarus_models::types::MusicType::FlacExtension,
|
||||
true,
|
||||
)
|
||||
.unwrap();
|
||||
song.directory = icarus_envy::environment::get_root_directory().value;
|
||||
song.filename =
|
||||
simodels::song::generate_filename(simodels::types::MusicType::FlacExtension, true)
|
||||
.unwrap();
|
||||
song.directory = sienvy::environment::get_root_directory().value;
|
||||
|
||||
match repo_queue::song::get_data(&pool, &payload.song_queue_id).await {
|
||||
Ok(data) => {
|
||||
@@ -340,7 +338,7 @@ pub mod endpoint {
|
||||
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
|
||||
) -> (axum::http::StatusCode, axum::response::Response) {
|
||||
match repo::song::get_song(&pool, &id).await {
|
||||
Ok(song) => match icarus_models::song::io::to_data(&song) {
|
||||
Ok(song) => match simodels::song::io::to_data(&song) {
|
||||
Ok(data) => {
|
||||
let bytes = axum::body::Bytes::from(data);
|
||||
let mut response = bytes.into_response();
|
||||
|
||||
+15
-20
@@ -28,20 +28,18 @@ mod cors {
|
||||
axum::http::Method::POST,
|
||||
axum::http::Method::PUT,
|
||||
axum::http::Method::DELETE,
|
||||
]) // Specify allowed methods:cite[2]
|
||||
])
|
||||
.allow_headers([
|
||||
axum::http::header::CONTENT_TYPE,
|
||||
axum::http::header::AUTHORIZATION,
|
||||
]) // Specify allowed headers:cite[2]
|
||||
.allow_credentials(true) // If you need to send cookies or authentication headers:cite[2]
|
||||
])
|
||||
.allow_credentials(true)
|
||||
.max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2]
|
||||
|
||||
// Dynamically set the allowed origin based on the environment
|
||||
match std::env::var(icarus_envy::keys::APP_ENV).as_deref() {
|
||||
match std::env::var(sienvy::keys::APP_ENV).as_deref() {
|
||||
Ok("production") => {
|
||||
// In production, allow only your specific, trusted origins
|
||||
let allowed_origins_env = icarus_envy::environment::get_allowed_origins();
|
||||
match icarus_envy::utility::delimitize(&allowed_origins_env) {
|
||||
let allowed_origins_env = sienvy::environment::get_allowed_origins();
|
||||
match sienvy::utility::delimitize(&allowed_origins_env) {
|
||||
Ok(alwd) => {
|
||||
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
|
||||
.into_iter()
|
||||
@@ -55,17 +53,14 @@ mod cors {
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// Development (default): Allow localhost origins
|
||||
cors.allow_origin(vec![
|
||||
"http://localhost:8000".parse().unwrap(),
|
||||
"http://127.0.0.1:8000".parse().unwrap(),
|
||||
"http://localhost:8001".parse().unwrap(),
|
||||
"http://127.0.0.1:8001".parse().unwrap(),
|
||||
"http://localhost:4200".parse().unwrap(),
|
||||
"http://127.0.0.1:4200".parse().unwrap(),
|
||||
])
|
||||
}
|
||||
_ => cors.allow_origin(vec![
|
||||
"http://localhost:8000".parse().unwrap(),
|
||||
"http://127.0.0.1:8000".parse().unwrap(),
|
||||
"http://localhost:8001".parse().unwrap(),
|
||||
"http://127.0.0.1:8001".parse().unwrap(),
|
||||
"http://localhost:4200".parse().unwrap(),
|
||||
"http://127.0.0.1:4200".parse().unwrap(),
|
||||
]),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +81,7 @@ mod cors {
|
||||
coverart_queue_responses::wipe_data_from_coverart_queue::Response, coverart_responses::get_coverart::Response,
|
||||
metadata_queue_responses::queue_metadata::Response, metadata_queue_responses::fetch_metadata::Response)),
|
||||
tags(
|
||||
(name = "Icarus API", description = "Web API to manage music")
|
||||
(name = "soaricarus API", description = "Web API to manage music")
|
||||
)
|
||||
)]
|
||||
struct ApiDoc;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ pub mod connection_settings {
|
||||
}
|
||||
|
||||
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
let database_url = icarus_envy::environment::get_db_url().value;
|
||||
let database_url = sienvy::environment::get_db_url().value;
|
||||
println!("Database url: {database_url}");
|
||||
|
||||
PgPoolOptions::new()
|
||||
|
||||
+19
-19
@@ -38,7 +38,7 @@ mod tests {
|
||||
pub const LIMIT: usize = 6;
|
||||
|
||||
pub async fn get_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
let tm_db_url = icarus_envy::environment::get_db_url().value;
|
||||
let tm_db_url = sienvy::environment::get_db_url().value;
|
||||
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
||||
sqlx::PgPool::connect_with(tm_options).await
|
||||
}
|
||||
@@ -51,7 +51,7 @@ mod tests {
|
||||
}
|
||||
|
||||
pub async fn connect_to_db(db_name: &str) -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
let db_url = icarus_envy::environment::get_db_url().value;
|
||||
let db_url = sienvy::environment::get_db_url().value;
|
||||
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
||||
sqlx::PgPool::connect_with(options).await
|
||||
}
|
||||
@@ -83,7 +83,7 @@ mod tests {
|
||||
}
|
||||
|
||||
pub async fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
||||
let database_url = icarus_envy::environment::get_db_url().value;
|
||||
let database_url = sienvy::environment::get_db_url().value;
|
||||
let parsed_url = url::Url::parse(&database_url)?;
|
||||
|
||||
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
||||
@@ -149,25 +149,25 @@ mod tests {
|
||||
pub fn token_fields() -> (String, String, String) {
|
||||
(
|
||||
String::from("What a twist!"),
|
||||
String::from("icarus_test"),
|
||||
String::from("icarus"),
|
||||
String::from("soaricarus_test"),
|
||||
String::from("soaricarus"),
|
||||
)
|
||||
}
|
||||
|
||||
pub const TEST_USER_ID: uuid::Uuid = uuid::uuid!("cc938368-615a-4694-b2ca-6e122fa31c52");
|
||||
|
||||
pub async fn test_token() -> Result<String, josekit::JoseError> {
|
||||
let key: String = icarus_envy::environment::get_secret_main_key().value;
|
||||
let key: String = sienvy::environment::get_secret_main_key().value;
|
||||
let (message, issuer, audience) = token_fields();
|
||||
|
||||
let token_resource = icarus_models::token::TokenResource {
|
||||
let token_resource = simodels::token::TokenResource {
|
||||
message: message,
|
||||
issuer: issuer,
|
||||
audiences: vec![audience],
|
||||
id: TEST_USER_ID,
|
||||
};
|
||||
|
||||
match icarus_models::token::create_token(&key, &token_resource, time::Duration::hours(1)) {
|
||||
match simodels::token::create_token(&key, &token_resource, time::Duration::hours(1)) {
|
||||
Ok((access_token, _some_time)) => Ok(access_token),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
@@ -289,7 +289,7 @@ mod tests {
|
||||
.uri(uri)
|
||||
.header(
|
||||
axum::http::header::CONTENT_TYPE,
|
||||
icarus_meta::detection::song::constants::mime::FLAC,
|
||||
simeta::detection::song::constants::mime::FLAC,
|
||||
)
|
||||
.header(
|
||||
axum::http::header::AUTHORIZATION,
|
||||
@@ -306,7 +306,7 @@ mod tests {
|
||||
) -> Result<axum::response::Response, std::convert::Infallible> {
|
||||
let mut form = MultipartForm::default();
|
||||
let _ = form.add_file(
|
||||
icarus_meta::detection::coverart::constants::JPEG_TYPE,
|
||||
simeta::detection::coverart::constants::JPEG_TYPE,
|
||||
"tests/I/Coverart-1.jpg",
|
||||
);
|
||||
|
||||
@@ -913,10 +913,10 @@ mod tests {
|
||||
let temp_file =
|
||||
tempfile::tempdir().expect("Could not create test directory");
|
||||
let test_dir = String::from(temp_file.path().to_str().unwrap());
|
||||
let song = icarus_models::song::Song {
|
||||
let song = simodels::song::Song {
|
||||
directory: test_dir,
|
||||
filename: icarus_models::song::generate_filename(
|
||||
icarus_models::types::MusicType::FlacExtension,
|
||||
filename: simodels::song::generate_filename(
|
||||
simodels::types::MusicType::FlacExtension,
|
||||
true,
|
||||
)
|
||||
.unwrap(),
|
||||
@@ -2219,20 +2219,20 @@ mod tests {
|
||||
coverart_directory: &String,
|
||||
coverart_filename: &String,
|
||||
) -> Result<(Vec<u8>, Vec<u8>), std::io::Error> {
|
||||
let song = icarus_models::song::Song {
|
||||
let song = simodels::song::Song {
|
||||
directory: song_directory.clone(),
|
||||
filename: song_filename.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let coverart = icarus_models::coverart::CoverArt {
|
||||
let coverart = simodels::coverart::CoverArt {
|
||||
directory: coverart_directory.clone(),
|
||||
filename: coverart_filename.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
match icarus_models::song::io::to_data(&song) {
|
||||
Ok(song_data) => match icarus_models::coverart::io::to_data(&coverart) {
|
||||
match simodels::song::io::to_data(&song) {
|
||||
Ok(song_data) => match simodels::coverart::io::to_data(&coverart) {
|
||||
Ok(coverart_data) => Ok((song_data, coverart_data)),
|
||||
Err(err) => Err(err),
|
||||
},
|
||||
@@ -2248,14 +2248,14 @@ mod tests {
|
||||
coverart_filename: &String,
|
||||
coverart_data: Vec<u8>,
|
||||
) -> Result<(), std::io::Error> {
|
||||
let song = icarus_models::song::Song {
|
||||
let song = simodels::song::Song {
|
||||
directory: song_directory.clone(),
|
||||
filename: song_filename.clone(),
|
||||
data: song_data,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let coverart = icarus_models::coverart::CoverArt {
|
||||
let coverart = simodels::coverart::CoverArt {
|
||||
directory: coverart_directory.clone(),
|
||||
filename: coverart_filename.clone(),
|
||||
data: coverart_data,
|
||||
|
||||
@@ -2,7 +2,7 @@ use sqlx::Row;
|
||||
|
||||
pub async fn create(
|
||||
pool: &sqlx::PgPool,
|
||||
coverart: &icarus_models::coverart::CoverArt,
|
||||
coverart: &simodels::coverart::CoverArt,
|
||||
song_id: &uuid::Uuid,
|
||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
@@ -36,7 +36,7 @@ pub async fn create(
|
||||
pub async fn get_coverart(
|
||||
pool: &sqlx::PgPool,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
|
||||
) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
SELECT id, title, directory, filename, file_type, song_id FROM "coverart" WHERE id = $1;
|
||||
@@ -50,7 +50,7 @@ pub async fn get_coverart(
|
||||
});
|
||||
|
||||
match result {
|
||||
Ok(row) => Ok(icarus_models::coverart::CoverArt {
|
||||
Ok(row) => Ok(simodels::coverart::CoverArt {
|
||||
id: row
|
||||
.try_get("id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
@@ -84,7 +84,7 @@ pub async fn get_coverart(
|
||||
pub async fn get_coverart_with_song_id(
|
||||
pool: &sqlx::PgPool,
|
||||
song_id: &uuid::Uuid,
|
||||
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
|
||||
) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
SELECT id, title, directory, filename, file_type, song_id FROM "coverart" WHERE song_id = $1;
|
||||
@@ -98,7 +98,7 @@ pub async fn get_coverart_with_song_id(
|
||||
});
|
||||
|
||||
match result {
|
||||
Ok(row) => Ok(icarus_models::coverart::CoverArt {
|
||||
Ok(row) => Ok(simodels::coverart::CoverArt {
|
||||
id: row
|
||||
.try_get("id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
@@ -132,7 +132,7 @@ pub async fn get_coverart_with_song_id(
|
||||
pub async fn delete_coverart(
|
||||
pool: &sqlx::PgPool,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
|
||||
) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
DELETE FROM "coverart"
|
||||
@@ -148,7 +148,7 @@ pub async fn delete_coverart(
|
||||
});
|
||||
|
||||
match result {
|
||||
Ok(row) => Ok(icarus_models::coverart::CoverArt {
|
||||
Ok(row) => Ok(simodels::coverart::CoverArt {
|
||||
id: row
|
||||
.try_get("id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
|
||||
+9
-11
@@ -2,7 +2,7 @@ use sqlx::Row;
|
||||
|
||||
pub async fn insert(
|
||||
pool: &sqlx::PgPool,
|
||||
song: &icarus_models::song::Song,
|
||||
song: &simodels::song::Song,
|
||||
) -> Result<(time::OffsetDateTime, uuid::Uuid), sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
@@ -52,7 +52,7 @@ pub async fn insert(
|
||||
pub async fn get_song(
|
||||
pool: &sqlx::PgPool,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<icarus_models::song::Song, sqlx::Error> {
|
||||
) -> Result<simodels::song::Song, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
SELECT * FROM "song" WHERE id = $1
|
||||
@@ -72,7 +72,7 @@ pub async fn get_song(
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap();
|
||||
|
||||
Ok(icarus_models::song::Song {
|
||||
Ok(simodels::song::Song {
|
||||
id: row
|
||||
.try_get("id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
@@ -145,9 +145,7 @@ pub async fn get_song(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_all_songs(
|
||||
pool: &sqlx::PgPool,
|
||||
) -> Result<Vec<icarus_models::song::Song>, sqlx::Error> {
|
||||
pub async fn get_all_songs(pool: &sqlx::PgPool) -> Result<Vec<simodels::song::Song>, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
SELECT * FROM "song";
|
||||
@@ -161,7 +159,7 @@ pub async fn get_all_songs(
|
||||
|
||||
match result {
|
||||
Ok(rows) => {
|
||||
let mut songs: Vec<icarus_models::song::Song> = Vec::new();
|
||||
let mut songs: Vec<simodels::song::Song> = Vec::new();
|
||||
|
||||
for row in rows {
|
||||
let date_created_time: time::OffsetDateTime = row
|
||||
@@ -169,7 +167,7 @@ pub async fn get_all_songs(
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap();
|
||||
|
||||
let song = icarus_models::song::Song {
|
||||
let song = simodels::song::Song {
|
||||
id: row
|
||||
.try_get("id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
@@ -250,9 +248,9 @@ pub async fn get_all_songs(
|
||||
pub async fn delete_song(
|
||||
pool: &sqlx::PgPool,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<icarus_models::song::Song, sqlx::Error> {
|
||||
) -> Result<simodels::song::Song, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
// icarus_models::song::Song,
|
||||
// simodels::song::Song,
|
||||
r#"
|
||||
DELETE FROM "song"
|
||||
WHERE id = $1
|
||||
@@ -273,7 +271,7 @@ pub async fn delete_song(
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
.unwrap();
|
||||
|
||||
Ok(icarus_models::song::Song {
|
||||
Ok(simodels::song::Song {
|
||||
id: row
|
||||
.try_get("id")
|
||||
.map_err(|_e| sqlx::Error::RowNotFound)
|
||||
|
||||
Reference in New Issue
Block a user