Skip to content

Commit

Permalink
add breaches query
Browse files Browse the repository at this point in the history
  • Loading branch information
n1nj4t4nuk1 committed Dec 15, 2024
1 parent bd38a07 commit 0fb5ed8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
12 changes: 6 additions & 6 deletions libs/cti/src/breaches/application/breach_query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ use crate::{breaches::domain::entities::breach::Breach, shared::domain::errors::

pub struct BreachQueryResponse {
pub error: Option<DomainError>,
pub cve: Option<Breach>,
pub breach: Option<Breach>,
}

impl BreachQueryResponse {
pub const RES_TYPE: &'static str = "BreachQueryResponse";

pub fn ok(cve: Breach) -> BreachQueryResponse {
pub fn ok(breach: Breach) -> BreachQueryResponse {
BreachQueryResponse {
error: None,
cve: Some(cve),
breach: Some(breach),
}
}

pub fn boxed_ok(cve: Breach) -> Box<BreachQueryResponse> {
let res = BreachQueryResponse::ok(cve);
pub fn boxed_ok(breach: Breach) -> Box<BreachQueryResponse> {
let res = BreachQueryResponse::ok(breach);
Box::new(res)
}

pub fn err(error: DomainError) -> BreachQueryResponse {
BreachQueryResponse {
error: Some(error),
cve: None,
breach: None,
}
}

Expand Down
54 changes: 54 additions & 0 deletions libs/cti/src/breaches/application/breaches_query_response.rs
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
}
}
3 changes: 2 additions & 1 deletion libs/cti/src/breaches/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ pub mod find_one;
pub mod update_one;

pub mod breach_command_response;
pub mod breach_query_response;
pub mod breach_query_response;
pub mod breaches_query_response;

0 comments on commit 0fb5ed8

Please sign in to comment.