Skip to content

Commit 757a968

Browse files
authored
Issue #77 Move Workers and Validators to application layer (#80)
* validator - move `Leader`/`Follower` validators to `application` * validator - move workers to `application` * validator - main.rs - re-arrange imports * sentry - domain - channel - repository - rename `create()` to `add()`
1 parent cb8bf4f commit 757a968

File tree

13 files changed

+16
-14
lines changed

13 files changed

+16
-14
lines changed

sentry/src/application/resource/channel/channel_create/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl ChannelCreateHandler {
3131
spec: channel_input.spec,
3232
};
3333

34-
let success = await!(self.channel_repository.create(channel)).is_ok();
34+
let success = await!(self.channel_repository.add(channel)).is_ok();
3535

3636
Ok(ChannelCreateResponse { success })
3737
}

sentry/src/domain/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ pub trait ChannelRepository: Debug + Send + Sync {
5757

5858
fn find(&self, channel_id: &ChannelId) -> RepositoryFuture<Option<Channel>>;
5959

60-
fn create(&self, channel: Channel) -> RepositoryFuture<()>;
60+
fn add(&self, channel: Channel) -> RepositoryFuture<()>;
6161
}

sentry/src/infrastructure/persistence/channel/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl ChannelRepository for MemoryChannelRepository {
8383
res_fut.boxed()
8484
}
8585

86-
fn create(&self, channel: Channel) -> RepositoryFuture<()> {
86+
fn add(&self, channel: Channel) -> RepositoryFuture<()> {
8787
let channel_found = match self.records.read() {
8888
Ok(reader) => reader.iter().find_map(|current| {
8989
if channel.id == current.id {

sentry/src/infrastructure/persistence/channel/memory_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fn saves_channels() {
174174

175175
// save the 2nd channel
176176
// this shouldn't change the order in any way
177-
await!(some_init.create(new_channel)).expect("Saving 2nd new channel");
177+
await!(some_init.add(new_channel)).expect("Saving 2nd new channel");
178178

179179
let params = ChannelListParams::new(valid_until_ge, 10, 1, None).unwrap();
180180
let channels_list: Vec<Channel> =
@@ -191,7 +191,7 @@ fn saves_channels() {
191191

192192
// save the 2nd channel
193193
// this shouldn't change the order in any way
194-
await!(some_init.create(new_channel)).expect("Saving 3rd new channel");
194+
await!(some_init.add(new_channel)).expect("Saving 3rd new channel");
195195

196196
let channels_list: Vec<Channel> =
197197
await!(some_init.list(&params)).expect("List the 3 total channels");
@@ -213,7 +213,7 @@ fn saving_the_same_channel_id_should_error() {
213213

214214
let same_channel_id = get_channel("ABC", &None, None);
215215

216-
let error = await!(repository.create(same_channel_id))
216+
let error = await!(repository.add(same_channel_id))
217217
.expect_err("It shouldn't be possible to save the same channel_id");
218218

219219
match error {

sentry/src/infrastructure/persistence/channel/postgres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl ChannelRepository for PostgresChannelRepository {
7272
unimplemented!("find() for Postgres still needs to be implemented")
7373
}
7474

75-
fn create(&self, _channel: Channel) -> RepositoryFuture<()> {
75+
fn add(&self, _channel: Channel) -> RepositoryFuture<()> {
7676
unimplemented!("create() for Postgres still needs to be implemented")
7777
}
7878
}

validator/src/application.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod validator;
2+
pub mod worker;

validator/src/infrastructure/worker.rs renamed to validator/src/application/worker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub mod single {
1111

1212
use domain::{Channel, SpecValidator};
1313

14+
use crate::application::validator::{Follower, Leader};
1415
use crate::domain::{ChannelRepository, Validator, Worker, WorkerFuture};
15-
use crate::infrastructure::validator::{Follower, Leader};
1616

1717
#[derive(Clone)]
1818
pub struct TickWorker {
@@ -95,8 +95,8 @@ pub mod infinite {
9595
use futures::future::{join, FutureExt};
9696
use tokio::timer::Delay;
9797

98+
use crate::application::worker::TickWorker;
9899
use crate::domain::{Worker, WorkerFuture};
99-
use crate::infrastructure::worker::TickWorker;
100100

101101
#[derive(Clone)]
102102
pub struct InfiniteWorker {

0 commit comments

Comments
 (0)