23 lines
582 B
Rust
23 lines
582 B
Rust
|
//! # Users service
|
||
|
|
||
|
use crate::db_connection;
|
||
|
use crate::models::{NewUser, User};
|
||
|
use crate::schema::users;
|
||
|
use crate::utils::time_utils::time;
|
||
|
use diesel::prelude::*;
|
||
|
|
||
|
/// Create a new account
|
||
|
pub async fn create_account(name: &str, email: &str) -> anyhow::Result<User> {
|
||
|
db_connection::execute(|conn| {
|
||
|
let res = diesel::insert_into(users::table)
|
||
|
.values(&NewUser {
|
||
|
name: name.trim(),
|
||
|
email: email.trim(),
|
||
|
time_create: time() as i64,
|
||
|
})
|
||
|
.get_result(conn)?;
|
||
|
|
||
|
Ok(res)
|
||
|
})
|
||
|
}
|