rusty-bever/src/db/users.rs

35 lines
683 B
Rust
Raw Normal View History

2021-08-22 16:45:01 +02:00
use diesel::{prelude::*, AsChangeset, Insertable, Queryable};
2021-08-22 16:24:59 +02:00
use serde::Serialize;
use uuid::Uuid;
2021-08-22 16:45:01 +02:00
use crate::{
errors::RBError,
schema::{users, users::dsl::*},
};
2021-08-22 16:24:59 +02:00
#[derive(Queryable, Serialize)]
2021-08-22 16:45:01 +02:00
pub struct User
{
2021-08-22 16:24:59 +02:00
pub id: Uuid,
pub username: String,
#[serde(skip_serializing)]
pub password: String,
#[serde(skip_serializing)]
pub blocked: bool,
pub admin: bool,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "users"]
2021-08-22 16:45:01 +02:00
pub struct NewUser
{
2021-08-22 16:24:59 +02:00
pub username: String,
pub password: String,
pub admin: bool,
}
2021-08-22 16:45:01 +02:00
pub fn all(conn: &PgConnection) -> crate::Result<Vec<User>>
{
2021-08-22 16:24:59 +02:00
users.load::<User>(conn).map_err(|_| RBError::DBError)
}