Compare commits
No commits in common. "881518cc8ffb446b2d858cc695e45ea3876a9539" and "499b1748cecdda7770e6f8f8e3bf662033877351" have entirely different histories.
881518cc8f
...
499b1748ce
10
src/db.rs
10
src/db.rs
|
@ -4,14 +4,6 @@ use diesel::prelude::*;
|
||||||
#[database("tenebrous_db")]
|
#[database("tenebrous_db")]
|
||||||
pub(crate) struct TenebrousDbConn(diesel::SqliteConnection);
|
pub(crate) struct TenebrousDbConn(diesel::SqliteConnection);
|
||||||
|
|
||||||
pub(crate) fn load_character_list(
|
|
||||||
conn: TenebrousDbConn,
|
|
||||||
for_user_id: i32,
|
|
||||||
) -> QueryResult<Vec<CharacterEntry>> {
|
|
||||||
use crate::schema::characters::dsl::*;
|
|
||||||
characters.filter(user_id.eq(for_user_id)).load(&*conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn load_character(
|
pub(crate) fn load_character(
|
||||||
conn: TenebrousDbConn,
|
conn: TenebrousDbConn,
|
||||||
character_id: i32,
|
character_id: i32,
|
||||||
|
@ -21,7 +13,7 @@ pub(crate) fn load_character(
|
||||||
characters
|
characters
|
||||||
.filter(id.eq(character_id))
|
.filter(id.eq(character_id))
|
||||||
.limit(1)
|
.limit(1)
|
||||||
.first(&*conn)
|
.first::<CharacterEntry>(&*conn)
|
||||||
.optional()
|
.optional()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub mod characters;
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Serialize, Debug)]
|
#[derive(Eq, PartialEq, Serialize, Debug)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub id: i32,
|
pub id: usize,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
use crate::db;
|
|
||||||
use crate::db::TenebrousDbConn;
|
use crate::db::TenebrousDbConn;
|
||||||
use crate::errors::Error;
|
|
||||||
use crate::models::{characters::CharacterEntry, User};
|
use crate::models::{characters::CharacterEntry, User};
|
||||||
use rocket::response::Redirect;
|
use rocket::response::Redirect;
|
||||||
use rocket_contrib::templates::Template;
|
use rocket_contrib::templates::Template;
|
||||||
|
@ -10,16 +8,31 @@ pub fn routes() -> Vec<rocket::Route> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn user_index(user: User, conn: TenebrousDbConn) -> Result<Template, Error> {
|
fn user_index(user: User, conn: TenebrousDbConn) -> Template {
|
||||||
use crate::routes::characters::TemplateContext;
|
use crate::routes::characters::TemplateContext;
|
||||||
let characters = db::load_character_list(conn, user.id)?;
|
let characters = vec![
|
||||||
|
CharacterEntry {
|
||||||
|
id: 1,
|
||||||
|
user_id: 1,
|
||||||
|
name: "Bob".to_string(),
|
||||||
|
viewable: true,
|
||||||
|
data: Some(vec![]),
|
||||||
|
},
|
||||||
|
CharacterEntry {
|
||||||
|
id: 2,
|
||||||
|
user_id: 1,
|
||||||
|
name: "Alice".to_string(),
|
||||||
|
viewable: true,
|
||||||
|
data: Some(vec![]),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
let context = TemplateContext {
|
let context = TemplateContext {
|
||||||
characters: characters,
|
characters: characters,
|
||||||
user: user,
|
user: user,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Template::render("index", &context))
|
Template::render("index", &context)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/", rank = 2)]
|
#[get("/", rank = 2)]
|
||||||
|
|
|
@ -13,5 +13,7 @@
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<p>Try going to <a href="/hello/YourName">/hello/YourName</a></p>
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
Loading…
Reference in New Issue