Skip to content

Commit

Permalink
twiq: Add use_case::worker_repository mod
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Sep 13, 2022
1 parent 002b86a commit 2675fe4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions twiq/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions twiq/crates/use_case/Cargo.toml
Expand Up @@ -8,4 +8,5 @@ edition = "2021"
[dependencies]
async-trait = "0.1.57"
domain = { path = "../domain" }
event_store_core = { path = "../event_store_core" }
thiserror = "1.0.33"
1 change: 1 addition & 0 deletions twiq/crates/use_case/src/lib.rs
@@ -1,2 +1,3 @@
pub mod command;
pub mod user_repository;
pub mod worker_repository;
31 changes: 31 additions & 0 deletions twiq/crates/use_case/src/worker_repository.rs
@@ -0,0 +1,31 @@
use async_trait::async_trait;
use event_store_core::event_id::EventId;

#[derive(Debug, Eq, PartialEq, thiserror::Error)]
pub enum Error {
#[error("unknown {0}")]
Unknown(String),
}

pub type Result<T, E = Error> = std::result::Result<T, E>;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum WorkerName {
CreateUserRequest,
}

#[async_trait]
pub trait WorkerRepository {
async fn find_last_event_id(worker_name: WorkerName) -> Result<Option<EventId>>;
async fn store_last_event_id(
worker_name: WorkerName,
before: Option<EventId>,
after: EventId,
) -> Result<()>;
}

pub trait HasWorkerRepository {
type WorkerRepository: WorkerRepository + Send + Sync;

fn worker_repository(&self) -> &Self::WorkerRepository;
}

0 comments on commit 2675fe4

Please sign in to comment.