tsk-176: Get all songs endpoint #177

Merged
kdeng00 merged 9 commits from tsk-176 into v0.2 2025-08-19 12:25:46 -04:00
Showing only changes of commit 14014c35f8 - Show all commits
+17 -14
View File
@@ -351,24 +351,25 @@ pub mod song_db {
} }
} }
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<icarus_models::song::Song>, sqlx::Error> {
let result = sqlx::query( let result = sqlx::query(
r#" r#"
SELECT * FROM "song"; SELECT * FROM "song";
"# "#,
) )
.fetch_all(pool) .fetch_all(pool)
.await .await
.map_err(|e| { .map_err(|e| {
eprintln!("Error querying data: {e:?}"); eprintln!("Error querying data: {e:?}");
}); });
match result { match result {
Ok(rows) => { Ok(rows) => {
let mut songs: Vec<icarus_models::song::Song> = Vec::new(); let mut songs: Vec<icarus_models::song::Song> = Vec::new();
for row in rows { for row in rows {
let date_created_time: time::OffsetDateTime = row let date_created_time: time::OffsetDateTime = row
.try_get("date_created") .try_get("date_created")
.map_err(|_e| sqlx::Error::RowNotFound) .map_err(|_e| sqlx::Error::RowNotFound)
@@ -448,9 +449,7 @@ pub mod song_db {
Ok(songs) Ok(songs)
} }
Err(_err) => { Err(_err) => Err(sqlx::Error::RowNotFound),
Err(sqlx::Error::RowNotFound)
}
} }
} }
@@ -1229,8 +1228,12 @@ pub mod endpoint {
} }
} }
pub async fn get_all_songs(axum::Extension(pool): axum::Extension<sqlx::PgPool>, pub async fn get_all_songs(
) -> (axum::http::StatusCode, axum::Json<super::response::get_songs::Response>) { axum::Extension(pool): axum::Extension<sqlx::PgPool>,
) -> (
axum::http::StatusCode,
axum::Json<super::response::get_songs::Response>,
) {
let mut response = super::response::get_songs::Response::default(); let mut response = super::response::get_songs::Response::default();
match super::song_db::get_all_songs(&pool).await { match super::song_db::get_all_songs(&pool).await {