-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make splash route have expected behavior
- Loading branch information
1 parent
76b9ffe
commit 6ca4863
Showing
1 changed file
with
15 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |