diff --git a/src/routes/splash.rs b/src/routes/splash.rs index d454174..9d2d50c 100644 --- a/src/routes/splash.rs +++ b/src/routes/splash.rs @@ -1,9 +1,20 @@ -use axum::{routing::get, Router}; +use crate::setup; +use axum::{http::StatusCode, routing::get, Router}; +use sqlite::State; pub fn route() -> Router { - Router::new().route("/splash", get(random_splash())) + Router::new().route("/splash", get(random_splash)) } -fn random_splash() -> String { - "Hello".to_owned() +async fn random_splash() -> (StatusCode, String) { + let conn = setup::initialise_sqlite_connection(); + let query = "SELECT splash FROM splashes ORDER BY RANDOM() LIMIT 1"; + + let mut statement = conn.prepare(query).unwrap(); + + while let Ok(State::Row) = statement.next() { + return (StatusCode::OK, statement.read::(0).unwrap()); + } + + return (StatusCode::INTERNAL_SERVER_ERROR, "".to_owned()); }