diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-01-19 13:15:50 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-01-19 13:15:50 +0100 |
commit | a3db0a3cdfaba887bdcec1748d341bd8ebf6ac47 (patch) | |
tree | 206af0224b0e85ee735e89398a054a66b7a25ac6 /src/models | |
parent | b57e94dec2a1954baf93a60749cddf3cab18a067 (diff) | |
download | rocket-blog-a3db0a3cdfaba887bdcec1748d341bd8ebf6ac47.tar.gz rocket-blog-a3db0a3cdfaba887bdcec1748d341bd8ebf6ac47.tar.bz2 rocket-blog-a3db0a3cdfaba887bdcec1748d341bd8ebf6ac47.zip |
Fix user model, and include in build.
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/mod.rs | 4 | ||||
-rw-r--r-- | src/models/user.rs | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/models/mod.rs b/src/models/mod.rs index 0d38f29..f6aba77 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -1,3 +1,7 @@ pub mod post; pub use self::post::Post; pub use self::post::NewPost; + +pub mod user; +pub use self::user::User; +pub use self::user::NewUser; diff --git a/src/models/user.rs b/src/models/user.rs index 0a41e3d..c3f4f72 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -3,7 +3,7 @@ use diesel::prelude::*; use schema::users; use utils; -#[derive(AsChangeset, FromForm, Identifiable, Serialize, Queryable)] +#[derive(AsChangeset, Clone, FromForm, Identifiable, Serialize, Queryable)] pub struct User { pub id: i32, pub username: String, @@ -15,7 +15,7 @@ pub struct User { #[derive(Default, FromForm, Insertable)] #[table_name="users"] pub struct NewUser { - pub username; String, + pub username: String, pub realname: Option<String>, pub email: Option<String>, pub password: String, @@ -24,11 +24,13 @@ pub struct NewUser { impl User { pub fn by_id(user_id: i32, conn: utils::DbConn) -> QueryResult<User> { use schema::users::dsl::*; - users.filter(id.eq(user_id)).load::<User>(&*conn).map(|v| v.pop()) + users.filter(id.eq(user_id)) + .load::<User>(&*conn) + .map(|ref v| v[0].clone()) } pub fn create(new_user: &NewUser, conn: utils::DbConn) -> QueryResult<User> { - use ::schema::posts::dsl::*; + use ::schema::users::dsl::*; diesel::insert_into(users) .values(new_user) .get_result(&*conn) |