admin/roles: new role
This commit is contained in:
parent
efaf2bda5a
commit
8fa2fb7ddc
6 changed files with 167 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use crate::error::Error;
|
||||
use crate::Role;
|
||||
use database::sqlx::SqliteExecutor;
|
||||
use database::Error as DatabaseError;
|
||||
use database::Roles as DatabaseRoles;
|
||||
use id::RoleID;
|
||||
|
||||
|
|
@ -23,4 +24,21 @@ impl Role {
|
|||
.map(Self::from)
|
||||
.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
pub async fn insert(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
name: &RoleID,
|
||||
label: &str,
|
||||
) -> Result<(), Error> {
|
||||
DatabaseRoles::insert(conn, &name.0, label)
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
DatabaseError::UniqueConstraintPrimaryKey => {
|
||||
Error::NameNotAvailable(name.to_string())
|
||||
}
|
||||
_ => e.into(),
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,7 @@
|
|||
pub enum Error {
|
||||
#[error("Database: {0}")]
|
||||
Database(#[from] database::Error),
|
||||
|
||||
#[error("The name \"{0}\" is not available.")]
|
||||
NameNotAvailable(String),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue