a bit of bonus; very funny that the endpoint is just one long chained statement now

main
znpra 1 year ago
parent e321b79b5c
commit 5198090d70

@ -16,5 +16,5 @@
false
]
},
"hash": "f17495d023bac377869af665478b21bb962599df4bf7f59dd8336dc538f5a8fb"
"hash": "a49c11570aff702c2e583a7e37a94fcb98c3a76db228002b01a93e74a747c44a"
}

@ -9,27 +9,6 @@ use rand::{ thread_rng, seq::IteratorRandom };
use sqlx::{SqlitePool, sqlite::SqlitePoolOptions};
async fn user_pronouns(
State(pool): State<SqlitePool>,
Path(user): Path<String>,
) -> Result<String, StatusCode> {
let res = sqlx::query!("SELECT pronouns
FROM pronouns
WHERE username == ?",
user)
.fetch_one(&pool)
.await
.map_err(|err| match err {
sqlx::Error::RowNotFound => StatusCode::NOT_FOUND,
_ => StatusCode::INTERNAL_SERVER_ERROR
})?;
res.pronouns
.split(';')
.choose(&mut thread_rng())
.map(ToOwned::to_owned)
.ok_or(StatusCode::NOT_FOUND)
}
#[tokio::main]
async fn main() {
let pool = SqlitePoolOptions::new()
@ -52,3 +31,25 @@ async fn main() {
.await
.unwrap();
}
async fn user_pronouns(
State(pool): State<SqlitePool>,
Path(user): Path<String>,
) -> Result<String, StatusCode> {
sqlx::query!("SELECT pronouns
FROM pronouns
WHERE username == ?",
user)
.fetch_one(&pool)
.await
.map_err(|err| match err {
sqlx::Error::RowNotFound => StatusCode::NOT_FOUND,
_ => StatusCode::INTERNAL_SERVER_ERROR
})?
.pronouns
.split(';')
.choose(&mut thread_rng())
.map(ToOwned::to_owned)
.ok_or(StatusCode::NOT_FOUND)
}

Loading…
Cancel
Save