use crate::db::{Dao, TenebrousDbConn}; use crate::errors::Error; use crate::models::characters::Visibility; use crate::models::{characters::StrippedCharacter, users::User}; use rocket::response::Redirect; use rocket_contrib::templates::Template; use serde::Serialize; pub fn routes() -> Vec { routes![index, user_index, proto_test] } /// Information to display to the user on their home page. #[derive(Serialize)] pub struct UserHomeContext<'a> { pub characters: &'a [StrippedCharacter], pub user: &'a User, } #[get("/")] async fn user_index(user: &User, conn: TenebrousDbConn<'_>) -> Result { let characters: Vec = conn .load_character_list(user.id) .await? .into_iter() .map(|c| c.as_visible_for(Some(user))) .filter_map(|c| c) .collect(); let context = UserHomeContext { characters: &characters, user: user, }; Ok(Template::render("index", &context)) } #[get("/", rank = 2)] fn index() -> Redirect { super::common::redirect_to_login() } use crate::models::proto::{cofd::*, Proto}; #[post("/proto-test", data = "")] async fn proto_test<'a>(buf: Proto) -> &'a str { println!("buf is {:#?}", buf); println!("str is: {}", buf.strength); "lol" }