use crate::model::{ role::Role, user::{SchnupperBetreuerUser, User, UserWithDetails}, }; use futures::future::join_all; use rocket::{get, request::FlashMessage, routes, Route, State}; use rocket_dyn_templates::{tera::Context, Template}; use sqlx::SqlitePool; #[get("/schnupper")] async fn index( db: &State, user: SchnupperBetreuerUser, flash: Option>, ) -> Template { let schnupperant = Role::find_by_name(db, "schnupperant").await.unwrap(); let user_futures: Vec<_> = User::all_with_role(db, &schnupperant) .await .into_iter() .map(|u| async move { UserWithDetails::from_user(u, db).await }) .collect(); let users: Vec = join_all(user_futures).await; let mut context = Context::new(); if let Some(msg) = flash { context.insert("flash", &msg.into_inner()); } context.insert("schnupperanten", &users); context.insert( "loggedin_user", &UserWithDetails::from_user(user.into(), db).await, ); Template::render("admin/schnupper/index", context.into_json()) } pub fn routes() -> Vec { routes![index] }