This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
Finished release [optimized] target(s) in 0.81 secs | |
x86_64-elf-strip filesystem/bin/timeout | |
sudo umount build/filesystem/ || true | |
Password: | |
umount: build/filesystem/: not currently mounted | |
rm -rf build/filesystem.bin build/filesystem/ | |
dd if=/dev/zero of=build/filesystem.bin bs=1048576 count=128 | |
128+0 records in | |
128+0 records out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If I have this everything works | |
use schema::users::dsl::*; | |
use schema::users; | |
fn authenticate_user(db: &Db, user_email: &str, password: &str) -> EndpointResult<User> { | |
let conn = &*db.pool().get()?; | |
let user = match users.filter(users::email.eq(user_email)).first::<User>(conn) { | |
Ok(user) => user, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Serialize, Deserialize, Insertable)] | |
#[table_name="users"] | |
pub struct NewUser { | |
pub name: String, | |
pub username: String, | |
pub email: String, | |
#[serde(rename(deserialize = "password"))] | |
#[serde(deserialize_with = "hash_user_password")] | |
pub hashed_password: String | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl From<NewUser> for NewUserReadyForInsertion { | |
fn from(user: NewUser) -> NewUserReadyForInsertion { | |
NewUserReadyForInsertion { | |
name: user.name, | |
username: user.username, | |
email: user.email, | |
// TODO: Adress this unwrap | |
hashed_password: hash(&user.password, DEFAULT_COST).unwrap() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[post("/users", data = "<new_user>", format = "application/json")] | |
fn create(db: State<Db>, new_user: JSON<NewUser>) -> EndpointResult<JSON<User>> { | |
let conn = &*db.pool().get()?; | |
let new_user = NewUserReadyForInsertion::from(new_user.0); | |
let user = diesel::insert(&new_user).into(users::table) | |
.get_result::<User>(conn)?; | |
Ok(JSON(user)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Insertable)] | |
#[table_name="users"] | |
pub struct NewUserReadyForInsertion { | |
pub name: String, | |
pub username: String, | |
pub email: String, | |
pub hashed_password: String | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[post("/users", data = "<new_user>", format = "application/json")] | |
fn create(db: State<Db>, new_user: JSON<NewUser>) -> EndpointResult<JSON<User>> { | |
let conn = &*db.pool().get()?; | |
let user = diesel::insert(&new_user.0).into(users::table) | |
.get_result::<User>(conn)?; | |
Ok(JSON(user)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::default::Default; | |
const DEFAULT_PER_PAGE: i64 = 10; | |
const DEFAULT_PAGE: i64 = 1; | |
#[derive(FromForm)] | |
pub struct Pagination { | |
per_page: Option<i64>, | |
page: Option<i64> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let env_str = &std_env::var("BLOG_ENV").unwrap_or(format!("development")); | |
let env = Env::from_str(env_str).unwrap(); | |
let db_config = DbConfig::load(&env).expect("Error loading DB configuration"); | |
let mut db = Db::new(db_config); | |
db.init(); | |
rocket::ignite() | |
.mount("/api/v1", routes![ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let env_str = &std_env::var("BLOG_ENV").unwrap_or(format!("development")); | |
let env = Env::from_str(env_str).unwrap(); | |
let db_config = DbConfig::load(&env).expect("Error loading DB configuration"); | |
let mut db = Db::new(db_config); | |
db.init(); | |
let api_v1_routes = routes![api_v1::posts::api_v1_posts_index, | |
api_v1::posts::api_v1_posts_create, | |
api_v1::posts::api_v1_posts_show, |