20 lines
485 B
Rust
20 lines
485 B
Rust
use crate::prelude::*;
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct Params {
|
|
search_string: String,
|
|
}
|
|
|
|
pub async fn search(
|
|
State(pool): State<Pool>,
|
|
Query(params): Query<Params>,
|
|
) -> sqlx::Result<Json<Vec<db::users::UserSearch>>, StatusCode> {
|
|
db::users::search_for_user(¶ms.search_string, &pool)
|
|
.take(20)
|
|
.try_filter(|user| future::ready(user.similarity > 0.1))
|
|
.try_collect()
|
|
.await
|
|
.handle_internal()
|
|
.map(Json)
|
|
}
|