2020-12-05 13:07:33 +00:00
|
|
|
use crate::db::{Dao, TenebrousDbConn};
|
2020-12-03 23:39:55 +00:00
|
|
|
use crate::errors::Error;
|
2020-12-07 20:32:02 +00:00
|
|
|
use crate::models::characters::Visibility;
|
|
|
|
use crate::models::{characters::StrippedCharacter, users::User};
|
2020-12-01 21:32:16 +00:00
|
|
|
use rocket::response::Redirect;
|
|
|
|
use rocket_contrib::templates::Template;
|
2021-01-15 20:32:09 +00:00
|
|
|
use serde::Serialize;
|
2020-12-01 21:32:16 +00:00
|
|
|
|
|
|
|
pub fn routes() -> Vec<rocket::Route> {
|
2020-12-27 21:03:10 +00:00
|
|
|
routes![index, user_index, proto_test]
|
2020-12-01 21:32:16 +00:00
|
|
|
}
|
|
|
|
|
2020-12-05 20:15:14 +00:00
|
|
|
/// Information to display to the user on their home page.
|
|
|
|
#[derive(Serialize)]
|
|
|
|
pub struct UserHomeContext<'a> {
|
2020-12-07 20:32:02 +00:00
|
|
|
pub characters: &'a [StrippedCharacter],
|
2020-12-05 20:15:14 +00:00
|
|
|
pub user: &'a User,
|
|
|
|
}
|
|
|
|
|
2020-12-01 21:32:16 +00:00
|
|
|
#[get("/")]
|
2020-12-29 23:06:41 +00:00
|
|
|
async fn user_index(user: &User, conn: TenebrousDbConn<'_>) -> Result<Template, Error> {
|
2020-12-07 20:32:02 +00:00
|
|
|
let characters: Vec<StrippedCharacter> = conn
|
2020-12-13 13:57:50 +00:00
|
|
|
.load_character_list(user.id)
|
|
|
|
.await?
|
2020-12-07 20:32:02 +00:00
|
|
|
.into_iter()
|
|
|
|
.map(|c| c.as_visible_for(Some(user)))
|
|
|
|
.filter_map(|c| c)
|
|
|
|
.collect();
|
2020-12-01 21:32:16 +00:00
|
|
|
|
2020-12-05 20:15:14 +00:00
|
|
|
let context = UserHomeContext {
|
|
|
|
characters: &characters,
|
2020-12-01 21:32:16 +00:00
|
|
|
user: user,
|
|
|
|
};
|
|
|
|
|
2020-12-03 23:39:55 +00:00
|
|
|
Ok(Template::render("index", &context))
|
2020-12-01 21:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/", rank = 2)]
|
|
|
|
fn index() -> Redirect {
|
2020-12-03 19:45:56 +00:00
|
|
|
super::common::redirect_to_login()
|
2020-12-01 21:32:16 +00:00
|
|
|
}
|
2020-12-27 21:03:10 +00:00
|
|
|
|
|
|
|
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"
|
|
|
|
}
|