aboutsummaryrefslogtreecommitdiffstats
path: root/src/models
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-07-31 22:13:30 +0200
committerHarald Eilertsen <haraldei@anduin.net>2018-07-31 22:13:30 +0200
commitd285d0525f86160a61067942346fb40f2bc5c797 (patch)
treefa7da0b2bf0de8604dafb8cf3a4aac68165ee56c /src/models
parenta1bba63fae68e7e6a680b14b674d9c47dfcf4862 (diff)
downloadrocket-blog-d285d0525f86160a61067942346fb40f2bc5c797.tar.gz
rocket-blog-d285d0525f86160a61067942346fb40f2bc5c797.tar.bz2
rocket-blog-d285d0525f86160a61067942346fb40f2bc5c797.zip
Implemet editing users.
Diffstat (limited to 'src/models')
-rw-r--r--src/models/user.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/models/user.rs b/src/models/user.rs
index 9587fd3..82a359b 100644
--- a/src/models/user.rs
+++ b/src/models/user.rs
@@ -18,10 +18,10 @@ impl User {
users.load::<User>(&*conn)
}
- pub fn by_id(user_id: i32, conn: utils::DbConn) -> QueryResult<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)
+ .load::<User>(&**conn)
.map(|ref v| v[0].clone())
}
@@ -38,6 +38,11 @@ impl User {
.get_result(&*conn)
}
+ pub fn update(user: &User, conn: &utils::DbConn) -> QueryResult<User> {
+ use ::schema::users::dsl::*;
+ user.save_changes(&*conn)
+ }
+
pub fn delete(user_id: i32, conn: utils::DbConn) -> QueryResult<User> {
use ::schema::users::dsl::*;
diesel::delete(users.filter(id.eq(user_id))).get_result::<User>(&*conn)