Skip to content

Commit

Permalink
make splash route have expected behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmanczak committed Jul 8, 2024
1 parent 76b9ffe commit 6ca4863
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/routes/splash.rs
Original file line number Diff line number Diff line change
@@ -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::<String, _>(0).unwrap());
}

return (StatusCode::INTERNAL_SERVER_ERROR, "".to_owned());
}

0 comments on commit 6ca4863

Please sign in to comment.