WP-02: contracts and failing tests for settings, mail, jobs and scheduler
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@ -3,6 +3,8 @@ use async_trait::async_trait;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::auth::{AccessClaims, AuthEvent, RefreshToken};
|
||||
use crate::jobs::{JobKind, JobRun, JobStatus};
|
||||
use crate::settings::SmtpSettings;
|
||||
use crate::user::{User, UserUpdate};
|
||||
use crate::DomainError;
|
||||
|
||||
@ -40,3 +42,37 @@ pub trait AccessTokenIssuer: Send + Sync {
|
||||
fn issue(&self, user: &User) -> Result<String, DomainError>;
|
||||
fn verify(&self, token: &str) -> Result<AccessClaims, DomainError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait SettingsRepository: Send + Sync {
|
||||
async fn get(&self, key: &str) -> Result<Option<String>, DomainError>;
|
||||
async fn set(&self, key: &str, value: &str) -> Result<(), DomainError>;
|
||||
}
|
||||
|
||||
/// Symmetric encryption for secrets at rest.
|
||||
pub trait Cipher: Send + Sync {
|
||||
fn encrypt(&self, plain: &str) -> Result<String, DomainError>;
|
||||
fn decrypt(&self, cipher_text: &str) -> Result<String, DomainError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait Mailer: Send + Sync {
|
||||
async fn send(
|
||||
&self,
|
||||
smtp: &SmtpSettings,
|
||||
to: &[String],
|
||||
subject: &str,
|
||||
body: &str,
|
||||
) -> Result<(), DomainError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait JobRunRepository: Send + Sync {
|
||||
async fn insert(&self, run: &JobRun) -> Result<(), DomainError>;
|
||||
async fn append_log(&self, id: Uuid, line: &str) -> Result<(), DomainError>;
|
||||
async fn finish(&self, id: Uuid, status: JobStatus) -> Result<(), DomainError>;
|
||||
async fn get(&self, id: Uuid) -> Result<Option<JobRun>, DomainError>;
|
||||
async fn list(&self, limit: u32) -> Result<Vec<JobRun>, DomainError>;
|
||||
async fn find_running(&self, kind: JobKind) -> Result<Option<JobRun>, DomainError>;
|
||||
async fn last_finished(&self, kind: JobKind) -> Result<Option<JobRun>, DomainError>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user