feat: Basic domain creation API

This commit is contained in:
selfhoster selfhoster 2026-09-14 21:05:23 +02:00
commit f1a2721cbe
6 changed files with 176 additions and 44 deletions

View file

@ -6,6 +6,7 @@ pub type BoxedError = Box<dyn std::error::Error + Send + Sync + 'static>;
#[derive(Debug)]
pub enum UserCreationError {
DomainNotFound(String),
UserAlreadyExists(UserRef),
Permissions,
}
@ -13,6 +14,7 @@ pub enum UserCreationError {
impl fmt::Display for UserCreationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DomainNotFound(domain) => write!(f, "No domain {domain} to create user in"),
Self::UserAlreadyExists(user) => write!(f, "User already exists: {user}"),
Self::Permissions => write!(f, "You do not have permissions to create this user"),
}
@ -20,3 +22,25 @@ impl fmt::Display for UserCreationError {
}
impl std::error::Error for UserCreationError {}
#[derive(Debug)]
pub enum DomainCreationError {
DomainAlreadyExists(String),
InvalidDomain(String),
}
impl fmt::Display for DomainCreationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DomainAlreadyExists(domain) => {
write!(f, "Cannot create domain {domain} because it already exists")
}
Self::InvalidDomain(domain) => write!(
f,
"Cannot create domain `{domain}` because it's not considered a valid domain"
),
}
}
}
impl std::error::Error for DomainCreationError {}