Model:
use rocket::serde::{Deserialize, Serialize};
use sea_orm::entity::prelude::*;
#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "account")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub name: String,
pub password: String,
pub role: Role,
pub employee_menu_access: Option<AccessLevel>,
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub creation_date: DateTimeWithTimeZone
}
#[derive(
EnumIter,
DeriveActiveEnum,
Clone,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Serialize,
Deserialize
)]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(13))")]
pub enum Role {
#[sea_orm(string_value = "Employee")]
Employee,
#[sea_orm(string_value = "Manager")]
Manager,
#[sea_orm(string_value = "Administrator")]
Administrator,
}
#[derive(EnumIter, DeriveActiveEnum, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(5))")]
pub enum AccessLevel {
#[sea_orm(string_value = "None")]
None,
#[sea_orm(string_value = "Read")]
Read,
#[sea_orm(string_value = "Write")]
Write
}
impl ActiveModelBehavior for ActiveModel {}
#[derive(Serialize, Deserialize)]
pub struct LoginAccountDTO {
pub name: String,
pub password: String
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RegisterAccountDTO {
pub name: String,
pub password: String,
pub role: Role,
pub employee_menu_access: Option<AccessLevel>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct UpdateAccountDTO {
pub name: Option<String>,
pub password: Option<String>,
pub role: Option<Role>,
pub employee_menu_access: Option<AccessLevel>,
}