scaffold workspace + domain crate (errors, ids, uuid_id macro)

This commit is contained in:
2026-07-12 01:00:50 +02:00
parent e3a65d8052
commit 3ff146615f
7 changed files with 1215 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
use thiserror::Error;
use uuid::Uuid;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum DomainError {
#[error("User not found: {0}")]
UserNotFound(Uuid),
#[error("User already exists: {0}")]
UserAlreadyExists(String),
#[error("Channel not found: {0}")]
ChannelNotFound(Uuid),
#[error("No active schedule for channel: {0}")]
NoActiveSchedule(Uuid),
#[error("Validation error: {0}")]
ValidationError(String),
#[error("Invalid timezone: {0}")]
TimezoneError(String),
#[error("Unauthenticated: {0}")]
Unauthenticated(String),
#[error("Forbidden: {0}")]
Forbidden(String),
#[error("Repository error: {0}")]
RepositoryError(String),
#[error("Infrastructure error: {0}")]
InfrastructureError(String),
}
impl DomainError {
pub fn validation(message: impl Into<String>) -> Self {
Self::ValidationError(message.into())
}
pub fn unauthenticated(message: impl Into<String>) -> Self {
Self::Unauthenticated(message.into())
}
pub fn forbidden(message: impl Into<String>) -> Self {
Self::Forbidden(message.into())
}
pub fn is_not_found(&self) -> bool {
matches!(
self,
DomainError::UserNotFound(_) | DomainError::ChannelNotFound(_)
)
}
pub fn is_conflict(&self) -> bool {
matches!(self, DomainError::UserAlreadyExists(_))
}
}
pub type DomainResult<T> = Result<T, DomainError>;