(client: web::Data<Client>, username: web::Path<String>)
| 25 | /// Gets the user with the supplied username. |
| 26 | #[get("/get_user/{username}")] |
| 27 | async fn get_user(client: web::Data<Client>, username: web::Path<String>) -> HttpResponse { |
| 28 | let username = username.into_inner(); |
| 29 | let collection: Collection<User> = client.database(DB_NAME).collection(COLL_NAME); |
| 30 | match collection.find_one(doc! { "username": &username }).await { |
| 31 | Ok(Some(user)) => HttpResponse::Ok().json(user), |
| 32 | Ok(None) => { |
| 33 | HttpResponse::NotFound().body(format!("No user found with username {username}")) |
| 34 | } |
| 35 | Err(err) => HttpResponse::InternalServerError().body(err.to_string()), |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /// Creates an index on the "username" field to force the values to be unique. |
| 40 | async fn create_username_index(client: &Client) { |
nothing calls this directly
no outgoing calls
no test coverage detected