|
|
|
@ -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)
|
|
|
|
|
}
|
|
|
|
|