This allows us to use a service implementation which returns a dummy user during development and the actual authenticated user during production. It also simplifies tests.
26 lines
634 B
Rust
26 lines
634 B
Rust
use std::{future::Future, sync::Arc};
|
|
use thiserror::Error;
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum ServiceError {
|
|
#[error("Database query error: {0}")]
|
|
DatabaseQueryError(#[from] dao::DaoError),
|
|
|
|
#[error("Forbidden")]
|
|
Forbidden,
|
|
}
|
|
|
|
pub trait HelloService {
|
|
fn hello(&self) -> impl Future<Output = Result<Arc<str>, ServiceError>> + Send;
|
|
}
|
|
|
|
pub trait PermissionService {
|
|
fn check_permission(
|
|
&self,
|
|
privilege: &str,
|
|
) -> impl Future<Output = Result<(), ServiceError>> + Send;
|
|
}
|
|
|
|
pub trait UserService {
|
|
fn current_user(&self) -> impl Future<Output = Result<Arc<str>, ServiceError>> + Send;
|
|
}
|