51 lines
1.3 KiB
Rust
51 lines
1.3 KiB
Rust
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_derive::Serialize;
|
|
|
|
pub fn routes() -> Vec<rocket::Route> {
|
|
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<Template, Error> {
|
|
let characters: Vec<StrippedCharacter> = 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 = "<buf>")]
|
|
async fn proto_test<'a>(buf: Proto<CofdSheet>) -> &'a str {
|
|
println!("buf is {:#?}", buf);
|
|
println!("str is: {}", buf.strength);
|
|
"lol"
|
|
}
|