-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd38a07
commit 0fb5ed8
Showing
3 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
libs/cti/src/breaches/application/breaches_query_response.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use cqrs::domain::query_bus_response::QueryBusResponse; | ||
|
||
use crate::{breaches::domain::entities::breach::Breach, shared::domain::errors::DomainError}; | ||
|
||
pub struct BreachesQueryResponse { | ||
pub error: Option<DomainError>, | ||
pub breaches: Vec<Breach>, | ||
} | ||
|
||
impl BreachesQueryResponse { | ||
pub const RES_TYPE: &'static str = "BreachesQueryResponse"; | ||
|
||
pub fn ok(breaches: Vec<Breach>) -> BreachesQueryResponse { | ||
BreachesQueryResponse { | ||
error: None, | ||
breaches, | ||
} | ||
} | ||
|
||
pub fn boxed_ok(breaches: Vec<Breach>) -> Box<BreachesQueryResponse> { | ||
let res = BreachesQueryResponse::ok(breaches); | ||
Box::new(res) | ||
} | ||
|
||
pub fn err(error: DomainError) -> BreachesQueryResponse { | ||
BreachesQueryResponse { | ||
error: Some(error), | ||
breaches: vec![], | ||
} | ||
} | ||
|
||
pub fn boxed_err(error: DomainError) -> Box<BreachesQueryResponse> { | ||
let res = BreachesQueryResponse::err(error); | ||
Box::new(res) | ||
} | ||
|
||
pub fn is_err(&self) -> bool { | ||
self.error.is_some() | ||
} | ||
|
||
pub fn is_ok(&self) -> bool { | ||
self.error.is_none() | ||
} | ||
} | ||
|
||
impl QueryBusResponse for BreachesQueryResponse { | ||
fn response_type(&self) -> String { | ||
Self::RES_TYPE.to_string() | ||
} | ||
|
||
fn as_any(&self) -> &dyn std::any::Any { | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters