From ba3b7cff0d06159c9089273552c6393ce701201c Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 1 Nov 2025 14:42:08 -0400 Subject: [PATCH 1/4] tsk-208: Moving config and endpoint code --- src/callers/mod.rs | 7 +++++++ src/config/host.rs | 8 ++++++++ src/config/mod.rs | 1 + src/main.rs | 25 +++---------------------- 4 files changed, 19 insertions(+), 22 deletions(-) create mode 100644 src/config/host.rs create mode 100644 src/config/mod.rs diff --git a/src/callers/mod.rs b/src/callers/mod.rs index 542c384..b938401 100644 --- a/src/callers/mod.rs +++ b/src/callers/mod.rs @@ -3,6 +3,8 @@ pub mod queue; pub mod song; pub mod endpoints { + pub const ROOT: &str = "/"; + pub const CREATESONG: &str = "/api/v2/song"; pub const GETSONGS: &str = "/api/v2/song"; pub const GETALLSONGS: &str = "/api/v2/song/all"; @@ -17,3 +19,8 @@ pub mod endpoints { pub mod response { pub const SUCCESSFUL: &str = "SUCCESSFUL"; } + +/// Basic handler that responds with a static string +pub async fn root() -> &'static str { + "Hello, World!" +} diff --git a/src/config/host.rs b/src/config/host.rs new file mode 100644 index 0000000..1fb74e4 --- /dev/null +++ b/src/config/host.rs @@ -0,0 +1,8 @@ + +/// Full hosting address that the application will be broadcasting +pub fn get_full() -> String { + format!("{ADDRESS}:{PORT}") +} + +pub const ADDRESS: &str = "0.0.0.0"; +pub const PORT: &str = "8080"; diff --git a/src/config/mod.rs b/src/config/mod.rs new file mode 100644 index 0000000..5361e40 --- /dev/null +++ b/src/config/mod.rs @@ -0,0 +1 @@ +pub mod host; diff --git a/src/main.rs b/src/main.rs index e028386..e25a950 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ pub mod auth; +pub mod config; pub mod callers; pub mod repo; @@ -41,7 +42,7 @@ async fn main() { // build our application with a route let app = init::app().await; - let listener = tokio::net::TcpListener::bind(get_full()).await.unwrap(); + let listener = tokio::net::TcpListener::bind(config::host::get_full()).await.unwrap(); axum::serve(listener, app).await.unwrap(); } @@ -139,7 +140,7 @@ pub mod init { pub async fn routes() -> axum::Router { axum::Router::new() - .route(crate::ROOT, get(crate::root)) + .route(crate::callers::endpoints::ROOT, get(crate::callers::root)) .route( crate::callers::queue::endpoints::QUEUESONG, post(crate::callers::queue::song::endpoint::queue_song).route_layer( @@ -304,27 +305,7 @@ pub mod init { } } -// TODO: Move elsewhere -fn get_full() -> String { - get_address() + ":" + &get_port() -} -// TODO: Move elsewhere -fn get_address() -> String { - String::from("0.0.0.0") -} -// TODO: Move elsewhere -fn get_port() -> String { - String::from("8000") -} - -// TODO: Move elsewhere -pub const ROOT: &str = "/"; -// TODO: Move elsewhere -// basic handler that responds with a static string -pub async fn root() -> &'static str { - "Hello, World!" -} #[cfg(test)] mod tests { -- 2.47.3 From 601ee1e092fa1677f769601efb4d3a20d810fa86 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 1 Nov 2025 14:43:28 -0400 Subject: [PATCH 2/4] tsk-208: Code formatting --- src/config/host.rs | 1 - src/main.rs | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/config/host.rs b/src/config/host.rs index 1fb74e4..1bb0417 100644 --- a/src/config/host.rs +++ b/src/config/host.rs @@ -1,4 +1,3 @@ - /// Full hosting address that the application will be broadcasting pub fn get_full() -> String { format!("{ADDRESS}:{PORT}") diff --git a/src/main.rs b/src/main.rs index e25a950..93b4b6e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ pub mod auth; -pub mod config; pub mod callers; +pub mod config; pub mod repo; pub mod db { @@ -42,7 +42,9 @@ async fn main() { // build our application with a route let app = init::app().await; - let listener = tokio::net::TcpListener::bind(config::host::get_full()).await.unwrap(); + let listener = tokio::net::TcpListener::bind(config::host::get_full()) + .await + .unwrap(); axum::serve(listener, app).await.unwrap(); } @@ -305,8 +307,6 @@ pub mod init { } } - - #[cfg(test)] mod tests { use std::io::Write; -- 2.47.3 From c3ddea3c7b40dff8a3d400b8a4e1fe09f7497305 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 1 Nov 2025 14:43:42 -0400 Subject: [PATCH 3/4] tsk-208: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e906045..8f6cc1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -964,7 +964,7 @@ dependencies = [ [[package]] name = "icarus" -version = "0.3.18" +version = "0.3.19" dependencies = [ "axum", "axum-extra", diff --git a/Cargo.toml b/Cargo.toml index 9e1af66..cb75948 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus" -version = "0.3.18" +version = "0.3.19" edition = "2024" rust-version = "1.90" -- 2.47.3 From e0ef0513bca27e87be23241ae719573899d48b4f Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 1 Nov 2025 14:50:45 -0400 Subject: [PATCH 4/4] tsk-208: Accidentally changed port --- src/config/host.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/host.rs b/src/config/host.rs index 1bb0417..f692adc 100644 --- a/src/config/host.rs +++ b/src/config/host.rs @@ -4,4 +4,4 @@ pub fn get_full() -> String { } pub const ADDRESS: &str = "0.0.0.0"; -pub const PORT: &str = "8080"; +pub const PORT: &str = "8000"; -- 2.47.3