aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/models/mod.rs4
-rw-r--r--src/models/user.rs10
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)